Thread
#multiplatform
    b

    Benjamin Deroche

    2 months ago
    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

    vanniktech

    2 months ago
    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

    Benjamin Deroche

    2 months ago
    But then the "actual" in androidMain and desktopMain will still have duplicated code
    v

    vanniktech

    2 months ago
    The platform relevant bits right, if that's almost all the code, then a module sounds better
    r

    ribesg

    2 months ago
    I have modules with like 2 lines of code
    russhwolf

    russhwolf

    2 months ago
    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

    Benjamin Deroche

    2 months ago
    @russhwolf That sound amazing, how does it work?
    russhwolf

    russhwolf

    2 months ago
    Something like this
    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

    vanniktech

    2 months ago
    That's the issue I've been looking for: https://youtrack.jetbrains.com/issue/KT-42466