What's the deal with android and java versions. I ...
# random
c
What's the deal with android and java versions. I don't get why I can use java 11 as my java home and still compile android code if android supports only java 7 (with some of 8)
l
JDK 11 can compile java 6/7/8 source code without issues.
And JDK 6/7/8 byte code is valide JDK 11+ byte code as well.
c
Gotcha. So basically since java 6/7/8 is forwards compatible then jdk 11,12... 16 can all compile it (and might even have some optimizations)?
j
i think it's that java is backwards compatible. The syntax hasn't been broken, and the compiler can emit, say, Java 6 or 8 bytecode
g
android supports only java 7 (with some of 8)
It’s not quite correct. You shouldn’t forget that Android doesn’t support .class files at all, it supports .dex, but D8 can convert (dex) Java 11 and even Java 14 .class files to dex files compatible with all Android devices, though it may support not all features and not all new java standard library apis
💯 3
c
The state of java on android always gets me confused. The IDE comes with one version of java, my java_home is another version, and android apps themselves can run a mix of features of other java langs. But thank you all for your help
👍 1
g
Different java version for ide, system (java home) and runtime is not Android specific, it's the same for any other JVM development
c
Oh really? Interesting.
g
ide version is a bundled distribution of java which used to run ide itself, it also can be used to compile or run your code. Java home is just your system java, you can use it instead to compile code And you can compile your app and run it on a different machine with any other JVM version (of course which has version higher than target compile version of your app)
👍 2
r
Found this thread! as i am thinking of updating my android project which runs on AGP 8.2 and Gradle 8.5 to JDK 21. I wasn't sure if JDK 21 bytecode generated will work. But, based on this comment looks like D8 should be able to create .dex file which will be compatible for Android devices. Java language (sourceCompatibilty) shouldn't be a concern if it's set to JDK 21 - as the project is kotlin and backed by lint compiler based on minSDK.
If my understanding is correct, can you please point me to the D8 doc - which states the same theory. TBVH, i didn't find/read regarding it anywhere 😄
g
Latest supported of Java limited on 2 levels: 1. Gradle 2. Android Gradle Plugin
So what I said in my old comment it's correct, but it doesn't mean that current D8 supports any modern java version, there is usually time until it supported
👍 1
1. Gradle already supports Java 21 https://docs.gradle.org/current/userguide/compatibility.html 2. I don't know official page which tells Java/AGP compatibility, it's unfortunate, so I would suggest just try, if it compiles, it's fine, just do not expect desugaring outside of APIs mentioned here: https://developer.android.com/studio/write/java8-support-table
r
Makes sense. Thanks 🙏