https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
z

zt

03/01/2024, 3:07 AM
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

Jeff Lockhart

03/01/2024, 3:19 AM
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

zt

03/01/2024, 8:26 AM
Perfect, thank you!
👍 1
3 Views