https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
a

Ali Khaleqi Yekta

05/31/2022, 3:24 PM
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

rocketraman

05/31/2022, 4:26 PM
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

martmists

05/31/2022, 5:05 PM
According to the documentation that's not currently possible:
m

Mitchell Syer

05/31/2022, 5:13 PM
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

Michael Paus

05/31/2022, 5:13 PM
As a compromise I use 11 for both. Why do you need 17?
a

Ali Khaleqi Yekta

06/01/2022, 10:02 AM
@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

martmists

06/01/2022, 10:04 AM
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

Ali Khaleqi Yekta

06/01/2022, 10:05 AM
@Mitchell Syer How did you exactly compile to bytecode of JDK 11? Doesn't Android only support up to JDK 1.8?
m

Michael Paus

06/01/2022, 10:06 AM
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

Ali Khaleqi Yekta

06/01/2022, 10:06 AM
@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

martmists

06/01/2022, 10:09 AM
I moreso meant it as in adding an additional directory to both source sets, that way it would still be in a single folder
78 Views