I have a KMM project that target Android, iOS and ...
# multiplatform
b
I have a KMM project that target Android, iOS and desktop JVM. Is there any way to easily share a small part of code between Android and JVM? It's just 20 lines of code, it doesn't look enough to create a new separate module just for this 😔
v
I know I starred an issue for an intermediate source set just like iosMain, but I can't seem to find it. Your best option is to maybe expect/actual and just throw on iOS
b
But then the "actual" in androidMain and desktopMain will still have duplicated code
v
The platform relevant bits right, if that's almost all the code, then a module sounds better
r
I have modules with like 2 lines of code
r
You can do a shared android/jvm source set, but the IDE support is inconsistent. If it's only a small amount of code that might not be too big an issue.
b
@russhwolf That sound amazing, how does it work?
r
Something like this
Copy code
android()
jvm()
sourceSets {
    val androidMain by getting {}
    val jvmMain by getting {}
    val jvmCommonMain by creating {
        androidMain.dependsOn(this)
        jvmMain.dependsOn(this)
        dependsOn(commonMain)
    }
}
You may still need to manually write some copy/paste expect/actual declarations for dependencies that the Kotlin tooling doesn't correctly recognize are accessible to both android and jvm.
v
That's the issue I've been looking for: https://youtrack.jetbrains.com/issue/KT-42466