I'm making a multiplatform library. Currently I ha...
# multiplatform
z
I'm making a multiplatform library. Currently I have android, linuxx86 and jvm targets set up and in commonMain I have an expect declaration. Is there some way I can make the android target use the exact same actual declaration as the jvm one, so I don't need to reimplement the exact same code?
j
You can create a shared intermediate source set for Android and JVM. I assume you do have other code that needs Android-specific APIs. Otherwise Android could also consume the JVM target.
You can create a shared jvmCommon source set with:
Copy code
kotlin {
    @OptIn(ExperimentalKotlinGradlePluginApi::class)
    applyDefaultHierarchyTemplate {
        common {
            group("jvmCommon") {
                withAndroidTarget()
                withJvm()
            }
        }
    }
}
1
I'm doing this in my own library.
z
Perfect, thank you!
👍 1