本文介绍了在我的项目中使用jar时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Java 1.8来创建我的jar。
I use Java 1.8 to create my jar.
我可以在Java项目中使用它,但在Android项目中,我有以下错误:
I can use it in a Java project, but in an Android project, I have the following error:
Error:Error converting bytecode to dex: Cause: Dex cannot parse version 52 byte code. This is caused by library dependencies that have been compiled using Java 8 or above. If you are using the 'java' gradle plugin in a library submodule add targetCompatibility = '1.7' sourceCompatibility = '1.7' to that submodule's build.gradle file. Error:1 error; aborting Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.idemon.process.ProcessException: java.util.concurrent.ExecutionException: com.android.idemon.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'E:\Android-tool\JAVA\jdk1.8.0_77\bin\java.exe'' finished with non-zero exit value 1 Information:BUILD FAILED Information:Total time: 6.468 secs Information:3 errors Information:0 warnings Information:See complete output in console推荐答案
如果是多应用程序项目中的Java库,请使用下面提到的代码在库的build.gardle文件中。
In case of a Java library in a multi-app project, use code mentioned bellow in the library's build.gardle file.
apply plugin: 'java' sourceCompatibility = JavaVersion.VERSION_1_7 targetCompatibility = JavaVersion.VERSION_1_7 compileJava.options.bootClasspath = "D:/android/sdk/platforms/android-23/android.jar" ... dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) ... }您需要使用本地路径更改 compileJava.options.bootClasspath 到android.jar文件。这适用于Win10中的AS 2.2。 以获取更多参考资料,请访问 here
You will need to change compileJava.options.bootClasspath with your local path to android.jar file. This works for me in AS 2.2 on Win10. for more references please visit here
更多推荐
在我的项目中使用jar时出错
发布评论