Can the Android SDK work with JDK 1.7?

JavaAndroid

Java Problem Overview


I just installed the Android SDK R16 and JDK 7, but I keep getting the error

> Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead. Please use Android Tools > Fix Project Properties."

I am using some features of the JRE 1.7, so I can't just switch it to 1.6. How can I fix this problem?

Java Solutions


Solution 1 - Java

Yes, you can use Java 1.7 for the Android development. You must keep source compatibility with Java 6 during compile and only the next problem is because of the changed default algorithm for jarsigner.

This is solved in Stack Overflow question Android signing with Ant (workaround).

But it is already fixed in Ant. So the official support will be directly in the Android SDK soon.

If you want to use Maven for the build, the solution is in What kind of pitfals exist for the Android APK signing.

Update: Latest version of Ant, Maven Plugin or Gradle has no problem with Java 7 or Java 8, so this is already obsolete.

Solution 2 - Java

Starting with the ADT (22.6), it's possible to use Java 1.7 functionalities:

IMPORTANT:

The try-with-resources needs API 19 and above:

> Added support for Java 7 language features like multi-catch, > try-with-resources, and the diamond operator. These features require > version 19 or higher of the Build Tools. Try-with-resources requires > minSdkVersion 19; the rest of the new language features require > minSdkVersion 8 or higher.

Solution 3 - Java

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.

Solution 4 - Java

It's worth to mention that if you want compile project with API 21 (Android 5.0 Lollipop) you have to use JDK 1.7.

API 21 won't work with JDK 1.6 anymore.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioneBehbahaniView Question on Stackoverflow
Solution 1 - JavaATomView Answer on Stackoverflow
Solution 2 - Javaandroid developerView Answer on Stackoverflow
Solution 3 - JavaTomislav MarkovskiView Answer on Stackoverflow
Solution 4 - JavaklimatView Answer on Stackoverflow