eBehbahani
eBehbahani

Reputation: 1564

Can the Android SDK work with JDK 1.7?

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?

Upvotes: 61

Views: 77558

Answers (4)

klimat
klimat

Reputation: 24991

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.

Upvotes: 12

android developer
android developer

Reputation: 116402

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.

Upvotes: 29

ATom
ATom

Reputation: 16180

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.

Upvotes: 40

Tomislav Markovski
Tomislav Markovski

Reputation: 12346

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.

Upvotes: 19

Related Questions