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...?

Jeremy
  • 22,188
  • 4
  • 68
  • 81
Robert Louis Murphy
  • 1,558
  • 1
  • 16
  • 29

1 Answers1

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.

Yahel
  • 8,522
  • 2
  • 24
  • 32
  • 1
    "and there is no correlation anymore between the two." well that's not true? – keyser May 17 '12 at 14:59
  • @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. – Chris Stratton May 17 '12 at 15:03
  • @Keyser :If you care to elaborate :) – Yahel May 17 '12 at 15:04
  • 5
    Ok, I figured it out the byte code is compiled using Apache Harmony http://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. – Robert Louis Murphy May 17 '12 at 15:04
  • @ChrisStratton That makes more sense, and Yahel, I don't have the energy :p – keyser May 17 '12 at 15:05
  • 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. – Robert Louis Murphy May 17 '12 at 15:06
  • In summary, your answer does not answer my question. But if you carefully read http://en.wikipedia.org/wiki/Android_(operating_system) that will lead you to http://en.wikipedia.org/wiki/Dalvik_(software) which will lead you to http://en.wikipedia.org/wiki/Apache_Harmony which lets you infer that most but not all Java SE 6 Keywords/Syntax/APIs is supported. – Robert Louis Murphy May 17 '12 at 15:08
  • @Keyser : Edited my answer with "there is no correlation 'version-wise' anymore between the two". Hope that makes it clearer. – Yahel May 17 '12 at 15:08
  • 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. – Robert Louis Murphy May 17 '12 at 15:11
  • 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). – Robert Louis Murphy May 17 '12 at 15:13
  • @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. – Chris Stratton May 17 '12 at 15:13
  • 1
    @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 :) – Yahel May 17 '12 at 15:16
  • 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. – Robert Louis Murphy May 17 '12 at 15:22
  • @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 :) – Yahel May 18 '12 at 09:15