Is there a way to set the bytecode version to 17 f...
# multiplatform
a
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:
Copy code
...
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
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.
m
According to the documentation that's not currently possible:
m
In one of my projects I do exactly this without issues(just with Jvm 11 for Android). Maybe run
gradlew clean
and try rebuilding
m
As a compromise I use 11 for both. Why do you need 17?
a
@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?
m
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
a
@Mitchell Syer How did you exactly compile to bytecode of JDK 11? Doesn't Android only support up to JDK 1.8?
m
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
👍 1
a
@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.
m
I moreso meant it as in adding an additional directory to both source sets, that way it would still be in a single folder
389 Views