Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 517
maysi Avatar asked Aug 02 '13 16:08

maysi


4 Answers

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.

like image 144
Friis1978 Avatar answered Nov 06 '22 06:11

Friis1978


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.

like image 43
ironmouse Avatar answered Nov 06 '22 05:11

ironmouse


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!

like image 15
hussulinux Avatar answered Nov 06 '22 06:11

hussulinux


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.

like image 4
C4F Avatar answered Nov 06 '22 06:11

C4F