问题描述
我试图通过编写应用程序,并与多个依赖(lambdj,org.json,GSON,okhttp)的模块组成一个简单的Android应用程序。
不过,我对这个编译错误,我无法弄清楚如何解决它(和哪里出了问题)
:应用程序:preDexDebug
意外的顶级例外:
了java.lang.RuntimeException:异常解析类
在com.android.dx.command.dexer.Main.processClass(Main.java:752)
在com.android.dx.command.dexer.Main.processFileBytes(Main.java:718)
在com.android.dx.command.dexer.Main.access $ 1200(Main.java:85)
在com.android.dx.command.dexer.Main $ FileBytesConsumer.processFileBytes(Main.java:1645)
在com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
在com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
在com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
在com.android.dx.command.dexer.Main.processOne(Main.java:672)
在com.android.dx.command.dexer.Main.processAllFiles(Main.java:574)
在com.android.dx.command.dexer.Main.runMonoDex(Main.java:311)
在com.android.dx.command.dexer.Main.run(Main.java:277)
在com.android.dx.command.dexer.Main.main(Main.java:245)
在com.android.dx.command.Main.main(Main.java:106)
com.android.dx.cf.iface.ParseException:引起糟糕的类文件魔术(cafebabe)或版本(0034.0000)
在com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
在com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
在com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
在com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
在com.android.dx.command.dexer.Main.parseClass(Main.java:764)
在com.android.dx.command.dexer.Main.access $ 1500(Main.java:85)
在com.android.dx.command.dexer.Main $ ClassParserTask.call(Main.java:1684)
在com.android.dx.command.dexer.Main.processClass(Main.java:749)
... 12更多
1错误;中止
错误:执行失败的任务:应用程序:preDexDebug。
> com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:过程'命令'C:\\ Program Files文件\\的Java \\ jdk1.8.0_31 \\斌\\ java.exe的''与非完零退出值1
资料:构建失败
这通常是通过使用Java的非Java的8个项目,反之亦然8库造成的。
有关我修复是只使用retrolambda在我的项目,我使用的库:
在主的build.gradle
文件:
buildscript {
库{
jcenter()
}
依赖{
类路径'com.android.tools.build:gradle:1.5.0 //注意:不要在这里把你的应用程序依赖关系;他们属于
//在单个模块的build.gradle文件
类路径'me.tatarka:gradle这个-retrolambda:3.2.4
}
}
然后在你的应用程序/库顶的build.gradle
文件:
应用插件:'me.tatarka.retrolambda
另外,还要确保将其设置为Java的8:
安卓{ ... compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
retrolambda在编译时插件的行为,适用Java8拉姆达支持到code,见对他们做的更多的信息。
I'm trying to compile a simple Android app composed by the app and a module with multiple dependencies (lambdj, org.json, gson, okhttp ).
But I have this error on compiling and I cannot figure out how to solve it (and where is the problem)
:app:preDexDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Exception parsing classes
at com.android.dx.command.dexer.Main.processClass(Main.java:752)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:718)
at com.android.dx.command.dexer.Main.access$1200(Main.java:85)
at com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1645)
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:672)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:574)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:311)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
at com.android.dx.command.Main.main(Main.java:106)
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:472)
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:764)
at com.android.dx.command.dexer.Main.access$1500(Main.java:85)
at com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1684)
at com.android.dx.command.dexer.Main.processClass(Main.java:749)
... 12 more
1 error; aborting
Error:Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_31\bin\java.exe'' finished with non-zero exit value 1
Information:BUILD FAILED
This is usually caused by using Java 8 libraries on non-Java 8 Projects or vice-versa.
For me the fix was to just use retrolambda on my project and the libraries I used:
in your main build.gradle
file:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'me.tatarka:gradle-retrolambda:3.2.4'
}
}
then on top of your app/library build.gradle
file:
apply plugin: 'me.tatarka.retrolambda'
Also make sure to set it up for Java 8:
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
retrolambda plugin act at compile time and apply Java8 lambda support to your code, see https://github.com/evant/gradle-retrolambda for more informations on what it does.
这篇关于摇篮构建失败 - 糟糕的类文件魔术(cafebabe)或版本(0034.0000)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!