Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execution failed for task: ':app:preDexDebug'

I am experiencing that famous ':app:preDexDebug'-error.

First of all: Cleaning the project or rebuilding it works without errors. Under default settings I set the project bytecode version to 1.7 and under SDK Location in the project structure the JDK location seems to be correct, too. After a while of researching I still did not find the solution for this problem.

The error occurs when I try to run the project under Android Studio. Like mentioned before, cleaning, rebuilding and syncing with Gradle works fine (looks like it - no errors).

This is what the gradle console shows:

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

As you see below, I removed the "compile android. ..."-line in my build.gradle, but it still didn't work. So here is my gradle build file:

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'])
}

It looks like Gradle has some problems with my JDK, but I don't know what kind of and how to fix them. I hope you guys can help.

EDIT: I found out, that version (0034.0000) means, that I am using Java 8. The strange thing is, that I definitely do not use Java 8. In Android Studio I defined the JDK-path to "C:\Program Files\Java\jdk1.7.0_67". This is 64-Bit Java (I am using Win 7 64-Bit btw.). Besides of that I have 32-Bit Java at "C:\Program Files (x86)\Java\jdk1.7.0_75", but I am not pointing on its location from Android Studio (I need both versions on my machine). Does anyone know, why Android Studio thinks, that I have Java 8 on my machine? As you can see in my gradle build file, I set the sourceCompatibility and the targetCompatibility to JavaVersion.VERSION_1_7. Are there any hidden settings somewhere in Android Studio, which define the Java 8 setting?

like image 545
KJaeg Avatar asked Mar 25 '15 12:03

KJaeg


3 Answers

Solved it.

What confused me: The output 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)" let me think, that the error comes out of some android libraries, because every JDK-setting was set to 1.7.

But I knew that somewhere Java 8 was used. It was really strange to me.

Solution: Even though the permament notify of using --stacktrace or --debug was shown, I did not know where to use them (it was not explained anywhere). After searching the settings I stumbled upon the textfield for this options. So I wrote "--debug" in it. This option gave me information about, what really causes the error. Thanks to the debug-mode the title of the library was given, which caused the error by using Java 8. Since Eclipse doesn't complain about that, nobody in my company took care of this. What let me think in return, that everything had to be correct.

To make things short: If you are experiencing errors, like many people before, but their solutions don't work or your case seems to be very special, just use "--debug". The true informations are hidden there.

like image 80
KJaeg Avatar answered Nov 05 '22 15:11

KJaeg


To add --debug (or--stacktrace) go to File .. Settings ..Build, Execution, Deploy .. Compiler .. Command Line Arguments

like image 28
KirbyJames Avatar answered Nov 05 '22 14:11

KirbyJames


Go to File > Other Settings> default Settings >Build, Execution, Deploy> Complier and add the following arguments to Command Line Arguments

--debug --stacktrace 

Screenshot here

like image 30
mangu23 Avatar answered Nov 05 '22 14:11

mangu23