我已经开始了一个新的Android Studio项目并为我正在开发的lib创建了一个新模块,但是当我构建项目时出现问题我收到了这个错误:
AGPBI: {"kind":"error","text":"Error converting bytecode to dex:\nCause: java.lang.RuntimeException: Exception parsing classes","sources":[{}],"original":"UNEXPECTED TOP-LEVEL EXCEPTION:\njava.lang.RuntimeException: Exception parsing classes\n\tat com.android.dx.command.dexer.Main.processClass(Main.java:752)\n\tat com.android.dx.command.dexer.Main.processFileBytes(Main.java:718)\n\tat com.android.dx.command.dexer.Main.access$1200(Main.java:85)\n\tat com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1645)\n\tat com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)\n\tat com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)\n\tat com.android.dx.command.dexer.Main.processOne(Main.java:672)\n\tat com.android.dx.command.dexer.Main.processAllFiles(Main.java:574)\n\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:311)\n\tat com.android.dx.command.dexer.Main.run(Main.java:277)\n\tat com.android.dx.command.dexer.Main.main(Main.java:245)\n\tat com.android.dx.command.Main.main(Main.java:106)\nCaused by: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)\n\tat com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)\n\tat com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)\n\tat com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)\n\tat com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)\n\tat com.android.dx.command.dexer.Main.parseClass(Main.java:764)\n\tat com.android.dx.command.dexer.Main.access$1500(Main.java:85)\n\tat com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1684)\n\tat com.android.dx.command.dexer.Main.processClass(Main.java:749)\n\t... 12 more\n","tool":"Dex"}
AGPBI: {"kind":"error","text":"1 error; aborting","sources":[{}]}
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_20\bin\java.exe'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 16.008 secs
我创建了一个新项目,里面没有内容,只有app模块上的MainActivity类和lib模块上的一个简单类,结果相同。对此有何解决方案?感谢。
答案 0 :(得分:0)
在编译一个纯java lib(没有android插件)在android上使用时你必须使用JDK 7,我使用的是JDK 8,这就是dex的问题。