简体   繁体   English

如何在Android项目构建路径中使用需要1.7合规级别的Java项目?

[英]How do I use a Java project that requires a 1.7 compliance level on an Android project build path?

I'm using Eclipse. 我正在使用Eclipse。 If I change the compliance level of the main (Android) project from 1.6 to 1.7, I get an error: 如果我将主(Android)项目的合规性级别从1.6更改为1.7,则会出现错误:

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

If I change the compliance level of the "library" (Java) project from 1.7 to 1.6, a lot of the code in it becomes invalid. 如果我将“库”(Java)项目的合规性级别从1.7更改为1.6,则其中的许多代码将变为无效。

Is going through the code of the Java project and fixing every error my single option here? 是否正在浏览Java项目的代码并修复我的单个选项中的每个错误?

Google just released Eclipse ADT 22.6 which adds support for Java 7 language features, http://developer.android.com/tools/sdk/eclipse-adt.html . 谷歌刚刚发布了Eclipse ADT 22.6,它增加了对Java 7语言功能的支持, http://developer.android.com/tools/sdk/eclipse-adt.html Once you upgrade to to the latest version of the plugin the Compiler compliance level will include the 1.7 option. 升级到最新版本的插件后,编译器合规性级别将包含1.7选项。

Try to clean your project, and fix android properties. 尝试清理您的项目,并修复Android属性。 Link here and here 链接在这里这里

I guess you can find your answer here: 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工具>修复项目属性

If that doesn't help, I'd suggest to update all android's sdk plugins. 如果这没有帮助,我建议更新所有android的sdk插件。 I've had similar issue, after updating android's sdk, but I've missed to update android build tools and that caused lot of errors - could be the same with you. 我有类似的问题,在更新android的sdk后,但我错过了更新android构建工具,这导致了很多错误 - 可能与你一样。

You can use jar builded with Java7 but only in case if it is not using any special features of java7, otherwise dx wont be able to convert jvm byte code to dalvic format. 您可以使用使用Java7构建的jar,但仅在不使用java7的任何特殊功能的情况下,否则dx将无法将jvm字节代码转换为dalvic格式。

But there is a one problem: default build process of android sdk (from eclipse eg) fails if it finds classes with wrong version (compiled with java7, dx generates warning and fails). 但是有一个问题:android sdk的默认构建过程(来自eclipse例如)如果找到错误版本的类(用java7编译,dx生成警告并失败)则失败。 You should pass some argument to dx to drop such warnings. 您应该将一些参数传递给dx以丢弃此类警告。 Android studio's and Idea's build process doesnt care about this warnings and dx tries co convert java byte code to dalvic despite class version. Android studio和Idea的构建过程并不关心这个警告,dx尝试将Java字节代码转换为dalvic尽管类版本。

Use IntelliJ IDEA instead of Eclipse. 使用IntelliJ IDEA而不是Eclipse。 In IDEA you can set the Product language level (in Project StructureProject ) separately from the Android SDK's. 在IDEA中,您可以将设备语言级别 (在项目结构项目中 )与Android SDK分开设置。 As long as your code only uses 1.7 features that don't affect the bytecode, it'll work (but the compiler will give you warnings). 只要您的代码仅使用不影响字节码的1.7功能,它就能工作(但编译器会给您警告)。 This way, you can use diamonds, switch on strings, and other syntactic sugar, but you might be out of luck with multi-catch. 通过这种方式,你可以使用钻石,打开弦乐和其他语法糖,但你可能会因为多次捕捉而失去运气。 In fact, you can even use experimental 1.8 features like annotations in strange places, but I haven't tested lambdas yet (since IDEA abbreviates the code anyway). 实际上,您甚至可以在奇怪的地方使用实验1.8功能,例如注释,但我还没有测试过lambdas(因为IDEA无论如何都缩写了代码)。 See the tag for more info. 有关详细信息,请参阅标记。

Since Android Studio is a special build of IntelliJ IDEA, it might have the same feature, but I haven't tried in that. 由于Android Studio是IntelliJ IDEA的特殊版本,因此它可能具有相同的功能,但我没有尝试过。

If your library really needs java 7, there is nothing you can do. 如果您的库真的需要java 7,那么您无能为力。

Otherwise, go to your library project settings, go to the Java Compiler settings, and select 1.6 .class files compatibility. 否则,转到库项目设置,转到Java编译器设置,然后选择1.6 .class文件兼容性。

If there are errors in your source files, it means your library uses java 7 functions that cannot be compiled in java 6 bytecode. 如果源文件中存在错误,则表示您的库使用的java 7函数无法在java 6字节码中编译。 You're screwed. 你完蛋了。

Otherwise, you can now export a .jar file that you can use in your android project. 否则,您现在可以导出可以在Android项目中使用的.jar文件。

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

相关问题 Android需要编译器合规性级别5.0或6.0。找到'1.7'而不是。请使用Android工具>修复项目属性 - Android requires compiler compliance level 5.0 or 6.0. Found '1.7' instead. Please use Android Tools > Fix Project Properties 将项目编译器符合性设置设置为1.7将项目JRE构建路径条目设置为“ JavaSE-1.7” - Set project compiler compliance settings to 1.7 Set project JRE build path entry to 'JavaSE-1.7' 如果我使用的库的源和目标级别为1.7,如何将我的项目编译为java 1.5? - How to compile my project to java 1.5 if the library I use has source and target level of 1.7? 如何手动将项目添加到另一个项目的构建路径? - How do I manually add a project to the build path of another project? 我如何用Maven构建这个Java项目? - How do I build this java project with maven? 如何在Eclipse项目中指定旧的JDK合规性? - How do I specify an old JDK compliance in an Eclipse project? 如何在Android项目的Java中使用weightSum? - How do I use weightSum in Java in Android project? 如何在Eclipse中的Android项目中使用Java项目? - How do you use a Java project in your Android project in Eclipse? 如何在GGTS中使Grails Maven项目使用Java 1.7? - How to make a Grails Maven project use Java 1.7 in GGTS? 我需要在Java项目中使用什么相对路径 - What relative path do I need to use in my Java Project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM