Java Version Update?

Another quick post as things here are extremely busy at the moment.

Gradle 9.8.0 now supports Java 27 but should you use that - for everything?


No. It wouldn't even work if you tried.


I previously concluded 17 was likely the best/safest choice for most projects, but now I think 21 might be a better choice unless you are building a library. 21 in a library would force anyone using your library to target 21 as well. Another reason not to move up to 21 would be legacy dependencies. If you are using old libraries as they may not be compatible. 


I think Java 21 is likely the best option for the full toolchain and build in most cases. My post from January this year - Android - Java Version covers the subject in some detail.


The Official Android Page specifies a build target of Java 17. I believe this is for compatibility reasons and that makes a lot of sense.


So Java 27...

While you can't target Java 27 for Android app bytecode (Kotlin and D8/R8 don't support class version 71 yet), if you have serious problems with compile times and memory, you may want to look at running the Gradle daemon on JDK 27 (via your Gradle JDK setting / GRADLE_LOCAL_JAVA_HOME). I believe it should have lower peak memory usage and so give performance benefits. These come from Compact Object Headers; object headers are reduced from 96 bits to 64 bits by default, which can shrink peak heap memory usage by 10–20% during heavy builds.

Note: If you're on JDK 25 LTS, you can also get this by adding -XX:+UseCompactObjectHeaders to your org.gradle.jvmargs.)

For your actual project compilation, check out my January post for the full breakdown—or just set jvmToolchain in one place:

kotlin {
// Should show up as version 65
jvmToolchain(21)
}

Links

Related Blog Posts

Official

Comments

Popular posts from this blog

Android AGP 8.x.x -> 9.0.0 Deprecations / Config Changes

KMP (Kotlin Multiplatform) Windows Quick Start

Android - Java Version