Does Android Support Jdk 6 or 7

Which Android versions run which Java versions?

and so, apparently, Android 4.0 does not support Java 7.

By your definition, Android does not support any version of Java. The java and javax classes in the Android SDK do not exactly match any version of Java, whether a numerical version (e.g., 6, 7, 8) or whatever you want to consider Java SE/EE/ME to be.

Is there an overview which clearly shows which Android versions come with which Java version

In terms of language features (e.g., lambda expressions), quoting the documentation:

Android Studio 3.0 and later supports all Java 7 language features and a subset of Java 8 language features that vary by platform version

Here, "Android Studio" is really referring to the build tools that compile your source code and create the Dalvik bytecode. Current tools can support all Java 7 and a few Java 8 features on all versions of Android. Additional Java 8 features are only available on API Level 24+, usually because they rely upon certain classes that were only added to the Android SDK at that point.

But your concern seems to be with classes and methods, in which case there is no simple mapping of any Java version to any Android version.

Moreover, you are using reflection to hack into framework classes, which means your results will not only vary by Android version but by device model, as device manufacturers can and do change the implementation of framework classes.

Does it matter what version of JDK I use in Android Studio?

Why do we need JDK when we are already using Android SDK? After all, we are not developing for JVM.

The Android build process depends on a number of tools from the JDK. Check out the build system overview documentation.
The first big piece we need from JDK is javac- all your source code written in Java needs to be compiled before it can be converted to the DEX foramt.

Once your code has been compiled, dexed, and packaged into an APK, we need jarsigner to sign the APK.

Is there any difference between using JDK 1.6, 1.7 and 1.8?
That depends on what features you are using from each. Older projects that don't use Java 7 features can use Java 6 without issue. I personally recommend Java 7 for most modern projects. If you can use it, why not?

There are some efforts out there to bring Java 8 features to Android, most notably gradle-retrolambda. Some of these require JDK 8 to compile properly.

Can the Android SDK work with JDK 1.7?

You just need 1.6 present on your PC. I had the same problem. Install 1.6 JDK, and add it as known JDK, but don't actually select it for your project.

Java 7 language features with Android

If you are using Android Studio, the Java 7 language should be enabled automatically without any patches. Try-with-resource requires API Level 19+, and NIO 2.0 stuff are missing.

If you can't use Java 7 features, see @Nuno's answer on how to edit your build.gradle.

The following is for historical interest only.


A small part of Java 7 can certainly be used with Android (note: I have only tested on 4.1).

First of all, you could not use Eclipse's ADT because it is hard-coded that only Java compiler 1.5 and 1.6 are compliant. You could recompile ADT but I find there is no simple way to do that aside from recompiling the whole Android together.

But you don't need to use Eclipse. For instance, Android Studio 0.3.2, IntelliJ IDEA CE and other javac-based IDEs supports compiling to Android and you could set the compliance even up to Java 8 with:

  • File → Project Structure → Modules → (pick the module at the 2nd pane) → Language level → (choose "7.0 - Diamonds, ARM, multi-catch, etc.")

Enabling Java 7 on IntelliJ

This only allows Java 7 language features, and you can hardly benefit from anything since a half of improvement also comes from the library. Features you could use are those which do not depend on the library:

  • Diamond operator (<>)
  • String switch
  • Multiple-catch (catch (Exc1 | Exc2 e))
  • Underscore in number literals (1_234_567)
  • Binary literals (0b1110111)

And these features cannot be used yet:

  • The try-with-resources statement — because it requires the non-existing interface "java.lang.AutoCloseable" (this can be used publicly in 4.4+)
  • The @SafeVarargs annotation — because "java.lang.SafeVarargs" does not exist

... "yet" :) It turns out that, although Android's library is targeting for 1.6, the Android source does contain interfaces like AutoCloseable and traditional interfaces like Closeable does inherit from AutoCloseable (SafeVarargs is really missing, though). We could confirm its existence via reflection. They are hidden simply because the Javadoc has the @hide tag, which caused the "android.jar" not to include them.

There is already as existing question How do I build the Android SDK with hidden and internal APIs available? on how to get those methods back. You just need to replace the existing "android.jar" reference of the current Platform with our customized one, then many of the Java 7 APIs will become available (the procedure is similar to that in Eclipse. Check Project Structure → SDKs.)

In additional to AutoCloseable, (only) the following Java 7 library features are also revealed:

  • Exception chaining constructors in ConcurrentModificationException, LinkageError and AssertionError
  • The static .compare() methods for primitives: Boolean.compare(), Byte.compare(), Short.compare(), Character.compare(), Integer.compare(), Long.compare().
  • Currency: .getAvailableCurrencies(), .getDisplayName() (but without .getNumericCode())
  • BitSet: .previousSetBit(), .previousClearBit(), .valueOf(), .toLongArray(), .toByteArray()
  • Collections: .emptyEnumeration(), .emptyIterator(), .emptyListIterator()
  • AutoCloseable
  • Throwable: .addSuppressed(), .getSuppressed(), and the 4-argument constructor
  • Character: .compare(), .isSurrogate(), .getName(), .highSurrogate(), .lowSurrogate(), .isBmpCodePoint() (but without .isAlphabetic() and .isIdeographic())
  • System: .lineSeparator() (undocumented?)
  • java.lang.reflect.Modifier: .classModifiers(), .constructorModifiers(), .fieldModifiers(), .interfaceModifiers(), .methodModifiers()
  • NetworkInterface: .getIndex(), .getByIndex()
  • InetSocketAddress: .getHostString()
  • InetAddress: .getLoopbackAddress()
  • Logger: .getGlobal()
  • ConcurrentLinkedDeque
  • AbstractQueuedSynchronizer: .hasQueuedPredecessors()
  • DeflaterOutputStream: the 3 constructors with "syncFlush".
  • Deflater: .NO_FLUSH, .SYNC_FLUSH, .FULL_FLUSH, .deflate() with 4 arguments

That's basically all. In particular, NIO 2.0 does not exist, and Arrays.asList is still not @SafeVarargs.

Can the Android SDK work with JDK 1.7?

You just need 1.6 present on your PC. I had the same problem. Install 1.6 JDK, and add it as known JDK, but don't actually select it for your project.



Related Topics



Leave a reply



Submit