In an Android project what's the purpose of `kotli...
# android
l
In an Android project what's the purpose of
kotlinOptions.jvmTarget
? I'm wondering because we don't write Java Code so what prevents me to set it to
16
?
c
Bytecode generated for JDK 1.6 and 1.8 by Kotlin is quite different (in particular, lambdas & default functions). In a regular JVM, that can create performance differences, JAR size differences, and interop differences. No idea if that's the case on Android though.
g
You can set target 16, but not sure that Android d8 supports desugaring of java 16 (though it does support at least java 14, but not all features and not all new additions to java standard library)
l
ok thanks, so the limiting factor is the D8 compiler (and the ART I guess). Then what confuses me, how can we know when and if Kotlin code poduces bytecode for, lets say Java 14, 15 or 16? It's important to know in order to set the right jvmTarget and to avoid breaking something
g
This option tells Kotlin compiler target JVM bytecode versions, there is version of bytecode in every .class file
how can we know when and if Kotlin code poduces bytecode for, lets say Java 14, 15 or 16
https://kotlinlang.org/docs/compiler-reference.html#jvm-target-version
to avoid breaking something
Yes, Android toolchain is the main limiting factor, check that it works thee first This is full list features supported by D8 desugaring: https://developer.android.com/studio/write/java8-support-table There is some level of native support on recent versions of Android, but as I understand it covers only Java 8