Gamadril

    Gamadril

    1 year ago
    How can I solve the "The 'java' plugin has been applied, but it is not compatible with the Android plugins." problem if my KMM module has to target both platforms: jvm and android
    andylamax

    andylamax

    1 year ago
    plugins {
      kotlin("multiplatform")
      // java - dont do this
    }
    Is enough to target both jvm and android
    Gamadril

    Gamadril

    1 year ago
    if I have java code in my jvmMain and provide
    kotlin {
        jvm {
            withJava()
        }
    }
    the java plugin is always applied automatically by kotlin.multiplatform plugin
    matej

    matej

    1 year ago
    @Gamadril I don't think you can have both a
    jvmMain
    and an
    androidMain
    in the same project yet, you have to pick one.
    Gamadril

    Gamadril

    1 year ago
    what's the sense of a Kotlin multiplatform module then? my jvmMain code is based on Springboot, androidMain is using android-only libraries. They are not compatible at all..
    andylamax

    andylamax

    1 year ago
    You van have
    jvmMain
    and
    androidMain
    plugins {
      id("com.android.library")
      kotlin("multiplatform")
    }
    
    kotlin {
      android {}
      jvm {
        // withJava() - not allowed if android {} is present
      }
    }
    hope that helps
    You also can have a common sourceSet for android and jvm
    c

    Casey Brooks

    1 year ago
    YOu can definitely have both JVM and Android targets, and optionally make Android extend JVM. Here’s the build script for a logging library I maintain that has separate JVM/Android sourcesets if you want a working example https://github.com/copper-leaf/clog/blob/master/clog-core/build.gradle.kts
    Gamadril

    Gamadril

    1 year ago
    @Casey Brooks: thanks, my build.gradle file looks similar to yours. However if you add withJava() inside jvm {} you will get the same error
    @andylamax: cannot find any note in official docs (https://kotlinlang.org/docs/mpp-configure-compilations.html#include-java-sources-in-jvm-compilations) that android {} is not allowed if jvm {} is used in combination with
    withJava()
    c

    Casey Brooks

    1 year ago
    That error is correct, he Android plugin is not compatible with the normal Java gradle plugin. It’s always been this way, even outside of Kotlin, and is not going to change. But you only need the java plugin applied if you’re using actual Java source files. If you’re writing the library in pure Kotlin source, it will still work just fine without using
    withJava()
    , you’ll still have access to all the Java stblib classes and any Java dependencies in your
    jvmMain
    sourceset
    If you do need to compile Java source files alongside your Kotlin ones, you’ll have to make separate Gradle modules for your Java and Android features