任务执行失败:':app:preDexDebug'

时间:2015-03-25 12:28:11

标签: exception android-studio build gradle build.gradle

我遇到了那个着名的':app:preDexDebug'-error。

首先:清理项目或重建项目没有错误。 在默认设置下,我将项目字节码版本设置为1.7,在项目结构中的SDK Location下,JDK位置似乎也是正确的。 经过一段时间的研究,我仍然没有找到解决这个问题的方法。

当我尝试在Android Studio下运行项目时发生错误。如前所述,清理,重建和与Gradle同步工作正常(看起来像 - 没有错误)。

这是gradle控制台显示的内容:

Configuration on demand is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:checkDebugManifest
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:compileDebugJava UP-TO-DATE
:app:preDexDebug
AGPBI: {"kind":"SIMPLE","text":"UNEXPECTED TOP-LEVEL EXCEPTION:","position":{},"original":"UNEXPECTED TOP-LEVEL EXCEPTION:"}
AGPBI: {"kind":"SIMPLE","text":"com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)","position":{},"original":"com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)","position":{},"original":"\tat com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)","position":{},"original":"\tat com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)","position":{},"original":"\tat com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)","position":{},"original":"\tat com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.processClass(Main.java:704)","position":{},"original":"\tat com.android.dx.command.dexer.Main.processClass(Main.java:704)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)","position":{},"original":"\tat com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.access$300(Main.java:83)","position":{},"original":"\tat com.android.dx.command.dexer.Main.access$300(Main.java:83)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)","position":{},"original":"\tat com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)","position":{},"original":"\tat com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)","position":{},"original":"\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)","position":{},"original":"\tat com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.processOne(Main.java:632)","position":{},"original":"\tat com.android.dx.command.dexer.Main.processOne(Main.java:632)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)","position":{},"original":"\tat com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)","position":{},"original":"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.run(Main.java:246)","position":{},"original":"\tat com.android.dx.command.dexer.Main.run(Main.java:246)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.main(Main.java:215)","position":{},"original":"\tat com.android.dx.command.dexer.Main.main(Main.java:215)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.Main.main(Main.java:106)","position":{},"original":"\tat com.android.dx.command.Main.main(Main.java:106)"}
AGPBI: {"kind":"SIMPLE","text":"...while parsing impl/org/controlsfx/ImplUtils.class","position":{},"original":"...while parsing impl/org/controlsfx/ImplUtils.class"}
AGPBI: {"kind":"SIMPLE","text":"1 error; aborting","position":{},"original":"1 error; aborting"}


 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_67\bin\java.exe'' finished with non-zero exit value 1

如下所示,我在build.gradle中删除了“compile android。...”行,但它仍然无效。 所以这是我的gradle构建文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion '22.0.1'
    compileOptions.encoding = 'windows-1251'

    defaultConfig {
        applicationId "de.giessen.advenco.key2operate"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
}

看起来Gradle在我的JDK上遇到了一些问题,但我不知道它们是什么类型以及如何修复它们。我希望你们能帮忙。

编辑:我发现,version (0034.0000)表示我使用的是Java 8.奇怪的是,我绝对不使用Java 8.在Android Studio中,我将JDK路径定义为{{ 1}}。这是64位Java(我使用的是Win 7 64-bit btw。)。除此之外,我在"C:\Program Files\Java\jdk1.7.0_67"有32位Java,但我没有指出它在Android Studio上的位置(我的机器上需要两个版本)。有谁知道,为什么Android Studio认为我的机器上有Java 8?正如您在我的gradle构建文件中所看到的,我将"C:\Program Files (x86)\Java\jdk1.7.0_75"sourceCompatibility设置为targetCompatibility。 Android Studio中是否有任何隐藏设置,它们定义了Java 8设置?

4 个答案:

答案 0 :(得分:1)

解决了它。

让我感到困惑的是:输出com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)","position":{},"original":"com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)"让我想到,错误来自一些android库,因为每个JDK设置都设置为1.7。

但我知道在某些地方使用了Java 8。这对我来说真的很奇怪。

解决方案:即使显示使用--stacktrace或--debug的permament通知,我也不知道在哪里使用它们(它没有在任何地方解释)。搜索完设置后,我偶然发现了这个选项的文本字段。所以我写了#34; - debug"在里面。此选项为我提供了有关错误的真正原因的信息。由于调试模式,给出了库的标题,这导致了使用Java 8的错误。由于Eclipse并没有抱怨,我公司没有人负责这一点。让我反思的是,一切都必须正确。

简而言之:如果您遇到错误,就像之前的许多人一样,但他们的解决方案不起作用或您的案例似乎非常特殊,只需使用" - debug"。真正的信息隐藏在那里。

答案 1 :(得分:1)

要添加--debug(或 - stacktrace),请转到文件..设置..构建,执行,部署..编译器..命令行参数

答案 2 :(得分:1)

转到文件>其他设置>默认设置>构建,执行,部署>编者 并将以下参数添加到命令行参数

--debug --stacktrace 

Screenshot here

答案 3 :(得分:0)

我有同样的问题。

对我而言:buildToolsVersion '21.1.2' 它将AGPBI显示为警告,但它仍然可以编译。