Hey there, in an Android project with 100% Kotlin ...
# android
Hey there, in an Android project with 100% Kotlin code, what benefits are there to target JVM 11 instead of 1.8?
Copy code
android {
    compileSdkVersion 33

    compileOptions {
      sourceCompatibility JavaVersion.VERSION_11
      targetCompatibility JavaVersion.VERSION_11

    kotlinOptions {
      jvmTarget = "11"
I assume the Android Gradle plugin will desugar the bytecode to be compatible with Java 1.8 (or 1.6?) so what are the benefits of letting the Gradle plugin do this instead of using 1.8 as JVM target?
Kotlin is compiled to java bytecode, and this bytecode is compiled to DEX code to work on android devices, targeting JAVA version 11 allows kotlin to benefit from newer bytecode enhancements & optimizations, so even if your project is fully written in kotlin, you will get additional benefits for targeting java bytecode version higher than 1.8. Also, it is worth mentioning that ART became a mainline module in Android 12 that would allow android devices to support newer java bytecode versions through a system update, Hence, it will be even possible to target bytecode versions higher than 11 when building android apps.
💯 1
Thanks for the clarification 👍🏼
I’m aware of the transformation process from Kotlin source code to ART bytecode. I was wondering if there are currently any technical advantages for developers and users when targeting JVM 11? Maybe a better runtime performance?
as I said above ☝️ kotlin can use that assumption to use new bytecode constructs, that eventually may lead to smaller bytecode size, and in turn smaller apps. I've not really benchmarked the difference in runtime performance between targeting older java bytecode version like 1.8 and targeting java bytecode version like 11, but as a rule of thumb I always follow: I would always use the highest java version as long as I'm not forced to do otherwise (that is the default for me at least, because targeting java 11 for example is definitely better than java 8 even if I'm not aware of all the gains that I will get)