Anybody getting this warning??
# multiplatform
c
Anybody getting this warning??
👀 3
m
d
All the time, unfortunately updating to v2 completely broke our setup (migration withstanding, it seems like variant support is removed?). @Matt Nelson Do you have Android variants in your project?
c
More reason why we are hesitant to upgrade to v2. Or were you able to fix it? @darkmoon_uk
d
No, as for a lot of folk, upgrading to 1.8.0/v2 is one of many competing priorities, so I returned it to the backlog for now... I got as far as confirming that for the otherwise same Gradle setup; Kotlin Multiplatform plugin was failing to create source sets to represent our Android variants as before, breaking the build.
m
Yeah it's problematic. I set up my projects to avoid all that completely, and have everything as an android library, then a separate
:app
module which is literally just the
Application
and depends on all the shared modules (setup as android libs). Then use DI to inject the build info (which will have the variant name). If you have a library with variants, you can do all you need in the
:app
module by specifying what dependency should be used for what variant
Copy code
// :app build.gradle.kts

android {
    // setup variants Alpha Beta
}

dependencies {
    "alphaImplementation"(project(":shared:lib-alpha"))
    "betaImplementation"(project(":shared:lib-beta"))
}
e
Are there any bugs filed on issuetracker/youtrack for the variant issue?
s
Hey, would somebody mind posting their used AS/AGP versions? We will then do some manual testing on it and potentially file a bug for the AS directly.
@Cherrio LLC: Would you mind sharing other reasons why you are hesitant upgrading to the new layout?
And just as an appendix: Android Variants are still supported in Layout2: The KotlinSourceSets will only be created when the variants are available, so maybe consider using onVariants from android or use a more lazy API like
Copy code
sourceSets.invokeWhenCreated("androidFreeDebug") {
        
 }
d
@Sebastian Sellmair [JB] Thanks for the guidance; you got us building again 🙏 🎉 Yes...
invokeWhenCreated("androidSomeFlavor") { ... }
...proved to be a straightforward replacement for the...
val androidSomeFlavor by getting { ... }
...that we had before. As you'll know better than me; before
1.8.0
, source sets were eagerly created from the Android model; so long as we took care to add the
android {...}
block before the
kotlin {...}
one, then
by getting
would reliably succeed. The creation eagerness change broke our build without giving us a clue why, and wasn't mentioned at all in the release notes as far as I know? I really think the
1.8.0
/ Android Source-set v2 layout documentation deserves to be amended with a paragraph about migrating from the old initialisation order. We can't be the only ones to get tripped up by this.