本文介绍了cordova错误:Dex:将字节码转换为dex时出错:原因:Dex无法解析版本52字节代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个离子项目.它已成功构建并在我的android手机中运行.从某天突然开始,当我运行命令"ionic cordova run android"时,出现以下构建错误:
I have a ionic project. It was successfully build and run in my android phone. suddenly from someday, when I run command "ionic cordova run android" I get the build error as below:
Dex: 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.
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Exception parsing classes
at com.android.dx.command.dexer.Main.processClass(Main.java:775)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:741)
at com.android.dx.command.dexer.Main.access$1200(Main.java:88)
at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1683)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:695)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:592)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:321)
at com.android.dx.command.dexer.Main.run(Main.java:292)
at com.android.builder.internal.compiler.DexWrapper.run(DexWrapper.java:54)
at com.android.builder.core.DexByteCodeConverter.lambda$dexInProcess$0(DexByteCodeConverter.java:173)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:476)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.parseClass(Main.java:787)
at com.android.dx.command.dexer.Main.access$1600(Main.java:88)
at com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1722)
at com.android.dx.command.dexer.Main.processClass(Main.java:773)
... 16 more
1 error; aborting
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Return code 1 for dex process
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Picked up _JAVA_OPTIONS: -Xmx256M
[ERROR] An error occurred while running subprocess cordova.
我尝试过"cordova clean",但是它不起作用.
I have tried "cordova clean", but it doesn't work.
您能帮我解决这个问题吗?
Could you please help me to solve this issue?
推荐答案
版本 52 字节代码与Java 8相对应,您需要在app/build.gradle
中添加以下内容,以使项目与Java 8
Version 52 byte code corresponds to Java 8, you need to add below to your app/build.gradle
to make your project be compatible with Java 8.
android {
...
defaultConfig {
jackOptions {
enabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
...
}
这篇关于cordova错误:Dex:将字节码转换为dex时出错:原因:Dex无法解析版本52字节代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!