Hi guys! I'm currently migrating from `com.android...
# multiplatform
g
Hi guys! I'm currently migrating from
com.android.library
to
com.android.kotlin.multiplatform.library
in my Android app. Suppose I have 2 modules: the application itself (which will keep
com.android.application
plugin) and the business logic module (which I'm migrating). Businesslogic has 2 flavors:
google
and
huawei
with different service implementations (for example, a push service). Since the new library plugin doesn't support flavors, my idea is to replace them with different sourceSets:
androidGoogleMain
and
androidHuaweiMain
, which the app will consume depending on it's flavor. But i get configuration error with this approach (more details in thread). What's the correct way to solve this problem?
This is how I configure new sourceSets:
Copy code
val androidMain by sourceSets.getting
    val androidGoogleMain by sourceSets.creating {
        dependsOn(androidMain)

        dependencies {
            implementation(libs.bundles.google)
        }
    }

    val androidHuaweiMain by sourceSets.creating {
        dependsOn(androidMain)

        dependencies {
            implementation(libs.bundles.huawei)
        }
    }
The errors I get:
Copy code
Unused Kotlin Source Sets
The following Kotlin source sets were configured but not added to any Kotlin compilation:
 * androidGoogleMain
 * androidHuaweiMain

Invalid Dependency on Default Compilation Source Set
Kotlin Source Set 'androidGoogleMain' can't depend on 'androidMain' which is a default source set for compilation.
None of source sets can depend on the compilation default source sets.
Solution: Please remove this dependency edge.
(2nd is the same for
androidHuaweiMain
)
I've tried another approach with adding new compilation:
Copy code
android {
        // namespace, etc..
        compilations {
            val main by getting
            val androidGoogleMain by creating {
                associateWith(main)
            }
        }
    }
Which gives exception:
Copy code
java.lang.IllegalStateException: Kotlin multiplatform android plugin doesn't support creating arbitrary compilations. Only three types of compilations are supported:
  * main compilation (named "main"),
  * host test compilation (use `kotlin.androidLibrary.withHostTest {}` to enable),
  * device test compilation (use `kotlin.androidLibrary.withDeviceTest {}` to enable).
I guess it's a specific of the new Android plugin that prevents me from replacing flavors with sourceSets?
h
You might have something like this in your build.gradle.kts of main module: kotlin {