Android Studio: Gradle - build fails -- Execution failed for task ':dexDebug'
Asked Answered
C

22

84

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?

Coati answered 2/8, 2013 at 16:29 Comment(0)
P
90

The right answer is, that some of your jar files does not compile. You should go into your build.gradle file in your project, and look in your dependencies.

If you're just importing some jar files, you could try to remove them and add them one at a time. This will help you determine which one of them causes the error.

In my case, I did just that, and when I was importing the last one, the app compiled. So I think the real problem was that I was importing too many at once. But now it all works.

Prevision answered 26/9, 2013 at 7:48 Comment(5)
If you compile using ./gradlew assemble --stacktrace --info it will let you know exactly which jar is badWafd
@NirHartmann Quick Question, is the command something i would place in the build gradle? I was not sure where it should be placed.Smoky
@Smoky not sure that I understand you question, I meant that in your root project directory you have an exec gradlew file, if you fire it from terminal or cmd like I said, you would know where the problem is and then you can fix it.Wafd
@Fallenreaper- have navigated to gradle/gradle in terminal and input ./gradlew assemble --stacktrace --info but get a no such dir, is this what you meant in your suggestion?Leidaleiden
This is really help full for meDemb
M
71

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.

Meeker answered 10/5, 2015 at 15:4 Comment(5)
Same problem here when adding an activity to replace the main activity. I performed a clean but it didn't work. Thanks for this solution.Phile
Also, try cleaning app/build folder in the library projects that you may be including in your appDolora
Good try but it did not fix my problem :/Oujda
fix my problem. Thank youAleris
Deleting build folder is really help full.Demb
C
15

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!

Carven answered 20/10, 2013 at 6:38 Comment(3)
This was technically correct for me, but happened because my dependencies in the build.gradle file had the android support library included twice with two different versions after adding a new activity to the project.Frightfully
I wasn't done when this was resolved, but it lead me on my way. Thanks.Crifasi
Solved a problem for me, but I would never have thought about the problem being duplicated JARs, from the error message. I had been importing Volley as a module at the project level, but because I wanted to be able to switch between building with AS and building with Cordova, I set up my environment to bring in Volley as a Cordova plugin. After regenerating the platform at some point, I then got this error message. Your comment about the same libraries being imported twice made me realise that I should have removed the 'Volley as imported library' settings, so thanks.Phyllisphylloclade
N
4

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.

Namtar answered 12/3, 2015 at 17:32 Comment(1)
Thanks! This solved my issue with Android Studio 1.4 and Gradle experimental-0.2.1 ;) I had to revert to JDK 1.7.1 though to fix completely this issueAugustinaaugustine
W
4

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

Walrus answered 25/3, 2015 at 21:25 Comment(1)
changing to gradle toots version 1.1.0 worked for me. thanks!Baler
G
4

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

Gamache answered 28/9, 2015 at 20:7 Comment(0)
H
3

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

Hijack answered 10/1, 2014 at 13:56 Comment(1)
In my case package name was duplicated in 2 library sub-projects.Lager
A
3

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"
Aundrea answered 8/11, 2015 at 10:28 Comment(0)
C
2

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

Coati answered 3/8, 2013 at 1:19 Comment(2)
Why 'v4:18.0.0'? Why not 'v4:+'Lilli
@Lilli because dynamic versions in general lead to unpredicted results.Cyril
H
1

I had the same problem, you should do:

File -> Invalidate Caches / Restart

Huh answered 22/10, 2015 at 13:25 Comment(0)
F
1

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'
}
Furred answered 17/11, 2015 at 12:28 Comment(0)
E
1

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'
Excurved answered 21/1, 2016 at 4:32 Comment(0)
S
0

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!

Silverfish answered 21/6, 2014 at 17:40 Comment(0)
M
0

(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.

Maxa answered 27/1, 2015 at 14:9 Comment(0)
C
0

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.

Constipation answered 8/4, 2015 at 13:43 Comment(1)
You should remove the local jars from the libs folder, and depend on Central repositories.Salmonoid
G
0

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 .

Goring answered 7/6, 2015 at 15:43 Comment(0)
D
0

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

Diagnose answered 4/10, 2015 at 14:35 Comment(0)
I
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.

Inveteracy answered 4/10, 2015 at 23:52 Comment(0)
A
0

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.

Arrack answered 2/11, 2015 at 16:20 Comment(0)
A
0

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

Assumpsit answered 25/12, 2015 at 23:22 Comment(0)
K
0

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"
    } 
Kobold answered 9/3, 2017 at 15:21 Comment(0)
L
-1

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

Lord answered 1/4, 2016 at 16:5 Comment(4)
Do you have any info as to why this would solve this issue?Intemperance
Coz in any which ways you can't exclude the libraries in build.gradle and the accepted solution is also telling us to remove and add the jar files that couldn't get compiled..So it was not those jar files that were causing trouble, they were working before the issue appeared and are still working after I resolved it using the method I mentioned, so its a build issue and the code didn't get compiled. So whats the best way when a build fails you clean the project and rebuild. Thank you!Lord
for most people this message appears if they are going to build their project. so this definitely not a solutionCoati
I hope you read the answer its a build failure due to dependencies not getting compiled and so it would appear when you "build the project" only .To stay in sync with your Android Studio also make sure you update Java to the latest available version coz it's a different story before and after it.Lord

© 2022 - 2024 — McMap. All rights reserved.