Thread
#multiplatform
    Ali Khaleqi Yekta

    Ali Khaleqi Yekta

    3 months ago
    Is there a way to set the bytecode version to 17 for the JVM, and to 1.8 for Android (for the common/shared module)? I tried setting:
    ...
    kotlin {
        android {
            compilations.all { kotlinOptions.jvmTarget = "1.8" }
        }
        jvm {
            compilations.all { kotlinOptions.jvmTarget = "17" }
        }
        ...
    }
    ...
    inside the
    build.gradle.kts
    of my common module, but when building the project, it fails with:
    ... error: cannot inline bytecode built with JVM target 17 into bytecode that is being built with JVM target 1.8. Please specify proper '-jvm-target' option ...
    r

    rocketraman

    3 months ago
    I think you'll need a multi-module structure to do this.. a shared module used by both JVM and Android targeting 1.8, and a JVM module targeting 17.
    martmists

    martmists

    3 months ago
    According to the documentation that's not currently possible:
    m

    Mitchell Syer

    3 months ago
    In one of my projects I do exactly this without issues(just with Jvm 11 for Android). Maybe run
    gradlew clean
    and try rebuilding
    Michael Paus

    Michael Paus

    3 months ago
    As a compromise I use 11 for both. Why do you need 17?
    Ali Khaleqi Yekta

    Ali Khaleqi Yekta

    3 months ago
    @rocketraman That's the approach I used to do, but I thought it might be good to benefit from the newer JDK versions' optimizations when possible. So for example, if the common code is compiled to bytecode of JDK 17 for the desktop and to 1.8 for Android, it can lead to smoother desktop (jvm target) experience.
    @martmists Thanks. Are you aware if there's any plan for it to be implemented anytime soon?
    martmists

    martmists

    3 months ago
    Instead of a shared source set maybe you can include the files in two separate source sets, but I'm not sure if the compiler allows that
    Ali Khaleqi Yekta

    Ali Khaleqi Yekta

    3 months ago
    @Mitchell Syer How did you exactly compile to bytecode of JDK 11? Doesn't Android only support up to JDK 1.8?
    Michael Paus

    Michael Paus

    3 months ago
    No, Android supports JDK 11 already for a long time and even higher byte code versions. Just in case someone wants some more detailed info on this:https://www.mobileit.cz/Blog/Pages/android-java-release-train.aspx https://developer.android.com/studio/releases/gradle-plugin#java-11
    Ali Khaleqi Yekta

    Ali Khaleqi Yekta

    3 months ago
    @Michael Paus Only to benefit more from the optimizations there might exist for the newer versions.
    @martmists That would be duplicating anything that exists in the common module, which doesn't sound interesting.
    martmists

    martmists

    3 months ago
    I moreso meant it as in adding an additional directory to both source sets, that way it would still be in a single folder