[android] Android Studio: Gradle - build fails -- Execution failed for task ':dexDebug'

Error:

Gradle: Execution failed for task ':vertretungsplan:dexDebug'.
> Failed to run command:
    P:\Android-Studio\sdk\build-tools\18.0.1\dx.bat --dex --output P:\Projekte\VertretungsplanProject\vertretungsplan\build\libs\vertretungsplan-debug.dex P:\Projekte\VertretungsplanProject\vertretungsplan\build\classes\debug P:\Projekte\VertretungsplanProject\vertretungsplan\build\dependency-cache\debug P:\Android-Studio\sdk\extras\android\m2repository\com\android\support\support-v4\18.0.0\support-v4-18.0.0.jar P:\Projekte\VertretungsplanProject\vertretungsplan\libs\commons-io-2.4.jar P:\Projekte\VertretungsplanProject\vertretungsplan\build\exploded-bundles\VertretungsplanProjectLibrariesActionbarsherlockUnspecified.aar\classes.jar
Error Code:
    2
Output:
    trouble processing:
    bad class file magic (cafebabe) or version (0033.0000)
    ...while parsing de/MayerhoferSimon/Vertretungsplan/LoginActivity$2.class
    ...while processing de/MayerhoferSimon/Vertretungsplan/LoginActivity$2.class
    trouble processing:
    bad class file magic (cafebabe) or version (0033.0000)
    ...while parsing de/MayerhoferSimon/Vertretungsplan/MainActivity$1.class
    ...while processing de/MayerhoferSimon/Vertretungsplan/MainActivity$1.class
    trouble processing:
    bad class file magic (cafebabe) or version (0033.0000)
    ...while parsing de/MayerhoferSimon/Vertretungsplan/YQL/YqlVplanParser.class
    ...while processing de/MayerhoferSimon/Vertretungsplan/YQL/YqlVplanParser.class
    3 warnings
    UNEXPECTED TOP-LEVEL EXCEPTION:
    com.android.dx.util.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
        at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:592)
        at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:550)
        at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:531)
        at com.android.dx.merge.DexMerger.mergeDexBuffers(DexMerger.java:168)
        at com.android.dx.merge.DexMerger.merge(DexMerger.java:186)
        at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:300)
        at com.android.dx.command.dexer.Main.run(Main.java:232)
        at com.android.dx.command.dexer.Main.main(Main.java:174)
        at com.android.dx.command.Main.main(Main.java:91)

Project structure:

enter image description here

build.gradle (actionbarsherlock)

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android-library'

dependencies {
    compile 'com.android.support:support-v4:18.0.0'
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.0.1"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 11
    }

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            res.srcDirs = ['res']
        }
    }
}

build.gradle (vertretungsplan)

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

dependencies {
    compile files('libs/commons-io-2.4.jar')
    compile project(':libraries:actionbarsherlock')
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.0.1"

    defaultConfig {
        minSdkVersion 8
        targetSdkVersion 11
    }
}

settings.gradle

include ':vertretungsplan', ':libraries:actionbarsherlock'

How can I fix this error?

This question is related to android gradle android-studio android-gradle-plugin

The answer is


The problem is NOT about Execution failed for task ':dexDebug'

if you look above the error showed in red you are going to see this

enter image description here

To solve this problem permanently just add these lines in your build.gradle file

android {
    dexOptions {
        jumboMode = true
    }
}

For further details check this question: here


I suddenly had the same problem, after no noteworthy changes.

I solved it by deleting the app/build directory and let gradle build the whole project new.


If you are also using Dagger or Butterknife you should to add guava as a dependency to your build.gradle main file like classpath :

com.google.guava:guava:20.0

In other hand, if you are having problems with larger heap for the Gradle daemon you can increase adding to your radle file:

 dexOptions {
        javaMaxHeapSize "4g"
    } 

I faced the same issue .Resolved by doing this . Go to actionbarsherlock -> module settings ->dependencies .Remove the support v4 library .In bottom left there is a plus button , from there add 1 Library Dependency (Select support-v4) . Let the gradle resync and clean project once done .


ANDROID STUDIO Users try this:-

You need to add the following to your gradle file dependencies:

compile 'com.android.support:multidex:1.0.0'

And then add below line ( multidex support application ) to your manifest's application tag:

android:name="android.support.multidex.MultiDexApplication"

Make sure your AndroidManifest file contains a package name in the manifest node. Setting a package name fixed this problem for me.


I got the same sort of error when I tried to compile a utils library jar in eclipse using Java JRE 1.8, and use it in my /libs/ in Android Studio 1.1.0.

I had my Android Studio set to use JDK1.8.0.

I switched my Eclipse to work with JRE 1.7, and the error was fixed. Eclipse: Window->Preferences->Java tab->Compiler -> Compliance level 1.7. It will most likely prompt you to switch your JRE System Library to jdk1.7.x_x.

You may need to make sure to uncheck 'compress jar' when you export. I haven't tested whether it had an effect or not. I doubt it was related.


A reason can be duplicated libraries after importing from Eclipse IDE.

dependencies {
compile 'com.github.japgolly.android:svg-android:2.0.5'
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:appcompat-v7:21.0.3'
compile files('libs/androidannotations-api-2.7.1.jar')
compile files('libs/androidasync-2.1.2.jar')
//compile files('libs/google-play-services.jar')
compile files('libs/universal-image-loader-1.8.2.jar')}

I had the same problem, after comment:

//compile files('libs/google-play-services.jar')

The app get no errors.


I had two incompatible dependencies.

The below dependencies caused the error.

compile 'com.google.android.gms:play-services-fitness:8.3.0'
compile 'com.google.android.gms:play-services-wearable:8.4.0'

By changing the fitness dependency to version 8.4.0 I was able to run the app.

compile 'com.google.android.gms:play-services-fitness:8.4.0'
compile 'com.google.android.gms:play-services-wearable:8.4.0'

I had the same problem, you should do:

File -> Invalidate Caches / Restart


I found a very interesting issue with Android Studio and the mircrosoft upgrade to the web browser. I upgraded "stupidly" to the latest version of ie. of course Microsoft in their infinite wisdom knows exactly what to do with security. When I tried to compile my app I kept getting the error Gradle - build fails -- Execution failed for task. looking in the stack I saw that it did not recognize the path to java.exe. I found that odd as I was just able to compile the day before. I added JAVA_HOME to the env vars for the system, closed Android Studio and reopened it. Low and behold if the fire wall nag screen did not pop asking if I wanted to all jave.exe through.

What a cluster!


I had the same problem too. In my case the problem started after a reboot. I closed my App, then I closed the Android Studio (In my case V1.1.0), and finally a normal shutdown. After that, I modified one java file to add a RadioGroup object and then the problem appeared.

I solved my problem only changing a simple '0' for a '1' in my Gradle configuration file, because the root cause of the problem was generated at the Gradle execution process. Previously I used to have version '1.0.0' then i changed it to '1.1.0', as stated in the pictures.

Location of the Gradle configuration a changed Location of the Gradle configuration a changed

Location where I took the right version from (File -> Settings -> Gradle -> Experimental Location where I took the right version from (File -> Settings -> Gradle -> Experimental


You must check if the same JAR is being imported again. In my case there was a class inside a jar which was getting imported in another jar. So just check if the any lib / class file is being included twice in the whole project!


(This might be the wrong thread, as your problem seems more specific, but it's the thread that I found when searching for the issue's keywords)

Despite all good hints, the only thing that helped me, and that I'd like to share just in case, if everything else does not work :

Remove your .gradle directory in your home directory and have it re-build/re-downloaded for you by Android Studio.

Fixed all kinds of weird errors for me that neither were fixable by re-installing Android Studio itself nor the SDK.


I had this problem because I tried to use both support library and appcompat:

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.android.support:support-v4:23.1.0'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.google.android.gms:play-services:8.3.0'
}

After I deleted support library and changed to older version, it compiled:

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    /*compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'*/
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:design:22.2.0'
    compile 'com.google.android.gms:play-services:8.3.0'
}

Many of the answers here are trial and error to find duplicate dependencies but if you scroll up just a little bit from the Execution failed for task ':app:dexDebug'. line it will give you a hint at the duplications

error with a hint.

In my case I had the following error:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define L/com/parse/AbstractQueryController$1;
...
...
...
Execution failed for task ':app:dexDebug'.

So I knew that in order to fix this bug I needed to find the duplicate dependencies that define parse.AbstractQueryController

In my case I had two imported modules that were loading in two different Parse libraries. Making my project only load one fixed my issue.


In my case, I did Build > Clean Project and it worked!


just add in build.gradle

compile 'com.parse.bolts:bolts-android:1.+'

compile 'com.parse:parse-android:1.11.0'

and sync Project with Gradle Files enter image description here But Don't Add The parse Jar in libs :) OKK


Cleaning the Project using Build in Menu Bar work for many error scenarios in Android Studio and so it does in this case.


Could fix this by adding

compile 'com.android.support:support-v4:18.0.0'

to the dependencies in the vertretungsplan build.gradle, compile and then remove this line and compile again.

now it works


I have also ran into this error when the package in one of my class files was incorrectly spelled. Many of these answers immediately jump to the Jar files but I would also check to make sure your packages are spelled correctly.


Examples related to android

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How to implement a simple scenario the OO way My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error java doesn't run if structure inside of onclick listener Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable how to put image in a bundle and pass it to another activity FragmentActivity to Fragment A failure occurred while executing com.android.build.gradle.internal.tasks

Examples related to gradle

Gradle - Move a folder from ABC to XYZ A failure occurred while executing com.android.build.gradle.internal.tasks Gradle: Could not determine java version from '11.0.2' Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0 Failed to resolve: com.android.support:appcompat-v7:28.0 Failed to resolve: com.google.firebase:firebase-core:16.0.1 com.google.android.gms:play-services-measurement-base is being requested by various other libraries java.lang.NoClassDefFoundError:failed resolution of :Lorg/apache/http/ProtocolVersion Error - Android resource linking failed (AAPT2 27.0.3 Daemon #0)

Examples related to android-studio

A failure occurred while executing com.android.build.gradle.internal.tasks "Failed to install the following Android SDK packages as some licences have not been accepted" error Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util This version of Android Studio cannot open this project, please retry with Android Studio 3.4 or newer WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()' Flutter plugin not installed error;. When running flutter doctor ADB.exe is obsolete and has serious performance problems Android design support library for API 28 (P) not working Flutter command not found How to find the path of Flutter SDK

Examples related to android-gradle-plugin

WARNING: API 'variant.getJavaCompile()' is obsolete and has been replaced with 'variant.getJavaCompileProvider()' Android Material and appcompat Manifest merger failed Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve Failed to resolve: com.google.firebase:firebase-core:16.0.1 com.google.android.gms:play-services-measurement-base is being requested by various other libraries Invoke-customs are only supported starting with android 0 --min-api 26 error: resource android:attr/fontVariationSettings not found Exception : AAPT2 error: check logs for details Could not resolve com.android.support:appcompat-v7:26.1.0 in Android Studio new project Failed to resolve: com.android.support:appcompat-v7:27.+ (Dependency Error)