简体   繁体   English

Android SDK可以与JDK 1.7一起使用吗?

[英]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 SDK R16和JDK 7,但我一直收到错误

Android requires compiler compliance level 5.0 or 6.0. Android需要编译器合规性级别5.0或6.0。 Found '1.7' instead. 找到'1.7'而不是。 Please use Android Tools > Fix Project Properties." 请使用Android工具>修复项目属性。“

I am using some features of the JRE 1.7, so I can't just switch it to 1.6. 我正在使用JRE 1.7的一些功能,所以我不能只将它切换到1.6。 How can I fix this problem? 我该如何解决这个问题?

Yes, you can use Java 1.7 for the Android development. 是的,您可以将Java 1.7用于Android开发。 You must keep source compatibility with Java 6 during compile and only the next problem is because of the changed default algorithm for jarsigner. 您必须在编译期间保持与Java 6的源兼容性,并且只有下一个问题是因为更改了jarsigner的默认算法。

This is solved in Stack Overflow question Android signing with Ant (workaround). 这是在使用Ant (解决方法)进行Android签名的 Stack Overflow问题中解决的。

But it is already fixed in Ant . 但它已经在Ant中得到修复 So the official support will be directly in the Android SDK soon. 因此,官方支持将很快直接在Android SDK中。

If you want to use Maven for the build, the solution is in What kind of pitfals exist for the Android APK signing . 如果你想使用Maven进行构建,那么解决方案就是Android APK签名中存在什么样的pitfals

Update: Latest version of Ant, Maven Plugin or Gradle has no problem with Java 7 or Java 8, so this is already obsolete. 更新:最新版本的Ant,Maven Plugin或Gradle对Java 7或Java 8没有任何问题,因此这已经过时了。

Starting with the ADT (22.6), it's possible to use Java 1.7 functionalities: 从ADT(22.6)开始,可以使用Java 1.7功能:

IMPORTANT: 重要:

The try-with-resources needs API 19 and above: try-with-resources需要API 19及更高版本:

Added support for Java 7 language features like multi-catch, try-with-resources, and the diamond operator. 添加了对Java 7语言功能的支持,如multi-catch,try-with-resources和diamond操作符。 These features require version 19 or higher of the Build Tools. 这些功能需要构建工具的19或更高版本。 Try-with-resources requires minSdkVersion 19; 尝试使用资源需要minSdkVersion 19; the rest of the new language features require minSdkVersion 8 or higher. 其余的新语言功能需要minSdkVersion 8或更高版本。

You just need 1.6 present on your PC. 您只需要在PC上使用1.6即可。 I had the same problem. 我有同样的问题。 Install 1.6 JDK, and add it as known JDK, but don't actually select it for your project. 安装1.6 JDK,并将其添加为已知的JDK,但实际上不要为您的项目选择它。

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(Android 5.0 Lollipop)编译项目,你必须使用JDK 1.7。

API 21 won't work with JDK 1.6 anymore. API 21将不再适用于JDK 1.6。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM