Error: Gradle: Execution Failed for Task ':App:Predexdebug'

Error: Gradle: execution failed for task ':app:preDexDebug'

We've seen this problem in the past when our project was compiling with a version of Java different from the one used to compile the library. The magic number is just used to identify class files so that is not the problem here. The issue is the java version (0034.0000 == Java 8).

The easiest thing to do is target Java 6, which may require removing newer syntax from your code. In our case, both the project and library were ours so we were able to add the following to force the version of Java that we needed:

Android Libraries

for android libraries, add this code to the "android" extension object:

android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
...
}

Java Libraries

for java libraries, add this code at the "top level":

apply plugin: 'java'

version '1.8.1'
group 'com.yourcompany.package'

sourceCompatibility = JavaVersion.VERSION_1_6 //these two lines
targetCompatibility = JavaVersion.VERSION_1_6 //are the only ones that matter

NOTE: the last two lines are the only ones that matter, I added the others just to show where those lines belong, in respect to the rest of your gradle build file.

Error:Execution failed for task ':app:dexDebug'.

I have figured it out, actually the problem was caused by

compile 'com.firebase:firebase-client-android:2.5.2'

which i have removed since its an old library,
and I think is a duplicate of

compile 'com.google.firebase:firebase-database:9.4.0'

which is the new library since Firebase changed as per point 3 of this article

changed to this:

compile 'com.google.firebase:firebase-database:9.4.0'
compile 'com.google.firebase:firebase-core:9.4.0'
compile 'com.firebaseui:firebase-ui:0.4.4'

Execution failed for task: ':app:preDexDebug'

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.

Gradle error - Execution failed for task ':app:dexDebug'

MPAndroidChart already has com.nineoldandroids:library:2.4.+ as a dependency. Remove compile 'com.nineoldandroids:library:2.4.0' from your dependencies.

Module dependency leads to Error:Gradle: Execution failed for task ':app:preDexDebug' in Android Studio

I have the same problem and I found the solution from this pure java unit tests tutorial, it said Android currently support is Java 1.7.

Adding pure Java unit tests to an Android project

In short, just set your java lib module to 1.7, so your build.gradle in mylib may like this.

apply plugin: 'java'

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

Hope this can help you.



Related Topics



Leave a reply



Submit