Which versions of Android SDK support coding in which versions of Java?
Asked Answered
H

1

10

I was writing an Android app for Android SDK 2.3.3 but then I was asked to test it on a device running Android 2.2.1. So I set my target to 8 instead of 10. But then java.util.concurrent.TimeUnit only had the Java 1.5 feature set instead of the Java 1.6/1.7 feature set of java.util.concurrent.TimeUnit. So I put the openjdk 6 implementation of TimeUnit into my package for my Android app and everything works fine.

Does anyone know where I can get some documentation that gives me a chart that tells me, for example, that when using the official SDK, Android 2.2 has to be coded using Java 1.5 keywords/syntax/APIs, Android 2.3.3 can be coded using Java 1.6 keywords/syntax/APIs, etc...?

Hydrobomb answered 17/5, 2012 at 14:41 Comment(3)
It seems strange to me that Android would ever force you to use 1.5, as Java 1.6 is older than Android. Maybe there's more going on here.Cohberg
I bet openjdk was only up to 1.5 at the time and that has something to do with it. openjdk 7 wasn't released until 2011/07/28Hydrobomb
duplicates: https://mcmap.net/q/36575/-how-does-android-39-s-java-version-relate-to-a-java-se-version/324625 and https://mcmap.net/q/36768/-jre-on-android/324625Metaphosphate
B
6

You are trying to look at Android as a subset of Java which it is not. They are completely separated. Even though Android comes from Java, it as departed from it quite a bit and there is no correlation 'version-wise' anymore between the two.

What you can look at is the Android documentation. For every instruction/command/method/properties, at the top right you'll find the api level at which you are able to access said property.

Clicking on the api level will take you to a page which contains a table that translates api level to Android versions.

The easy way to find out if you are allowed to use a property is using eclipse and doing what you just did : Change the target api level. Then any call to methods or properties that are not available to you will produce fatal errors.

Business answered 17/5, 2012 at 14:57 Comment(14)
"and there is no correlation anymore between the two." well that's not true?Wellfixed
@Keyser Yahel's point seems to be that you shouldn't try to map android versions to specific java versions in order to find out what is supported - instead you should directly check the Android documentation.Bartonbartosch
@Keyser :If you care to elaborate :)Business
Ok, I figured it out the byte code is compiled using Apache Harmony en.wikipedia.org/wiki/Apache_Harmony and then that byte code is converted to Dalvik byte code. I always thought that the Oracle JDK or whatever JDK you were using created the Java byte code that was later converted to Dalvik byte code. So Android 2.2 and before used the 99% complete Apache Harmony JDK 5.0. Android 2.3.3 and later use the 97% complete Apache Harmony Java SE 6. So features specific to JDK 7 and above can't be used when compiling Android apps using the official tools.Hydrobomb
@ChrisStratton That makes more sense, and Yahel, I don't have the energy :pWellfixed
And no, I never thought that Android was a subset of Java. I just thought the byte code that was being converted to Dalvik byte code came from what ever javac.exe I was using at the time, but it doesn't.Hydrobomb
In summary, your answer does not answer my question. But if you carefully read en.wikipedia.org/wiki/Android_(operating_system) that will lead you to en.wikipedia.org/wiki/Dalvik_(software) which will lead you to en.wikipedia.org/wiki/Apache_Harmony which lets you infer that most but not all Java SE 6 Keywords/Syntax/APIs is supported.Hydrobomb
@Keyser : Edited my answer with "there is no correlation 'version-wise' anymore between the two". Hope that makes it clearer.Business
Well there is a correlation: In testing, I found that some Java SE 6 features are supported in 2.3.3 but aren't supported in 2.2. Somewhere someone that worked on the project knows which version of Apache Harmony is used in 2.2 and which version of Apache Harmony is used in each subsequent version, and then from that I can use the Apache Harmony documentation to see which coding features are supported by each Android SDK, so far I haven't found that documentation.Hydrobomb
And so there is not confusion: Apache Harmony isn't used in Android, but it is used in the Android SDK build tools when you code in Java (perhaps when you code in C, but I don't know about that).Hydrobomb
@RobertLouisMurphy the compiler is that of the JDK, but the compiler has relatively little to do with what APIs are available. The API libraries found on the device and against which you build programs consist of selections from Harmony, other sources, and things developed uniquely for Android, rather than from Sun/Oracle.Bartonbartosch
@Robert : Sorry but there is no direct correlation at all between Android and Java versions. Java was the base upon which Android grew, leaving some things behind, adding new things as needed. You will only make your life harder by trying to work on a different documentation than the Android's one :)Business
Yahel - we all understand your point but it has little to do with the original question. Your statement that "there is no direct correlation at all between Android and Java versions" is like saying there is no direct correlation between Java source code and .class files. Just because there are a couple translation steps between the two does not mean there isn't any correlation.Hydrobomb
@Robert : Ok, maybe my english betrayed me :) I was sure you asked for a chart that would tell you what java instructions set is available when coding in a specific version of Android. Nevermind :)Business

© 2022 - 2024 — McMap. All rights reserved.