当前位置: 首页 > 知识库问答 >
问题:

Android Studio: Gradle-构建失败-任务执行失败:dexDebug

苍宝
2023-03-14

错误:

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)

项目结构:

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

建筑格拉德尔(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
    }
}

设置。格拉德尔

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

如何修复此错误?

共有3个答案

柴默
2023-03-14

您必须检查是否再次导入了相同的JAR。在我的例子中,一个jar中有一个类正在导入另一个jar中。所以只需检查整个项目中是否包含了两次lib/class文件!

倪鸿禧
2023-03-14

在没有明显变化之后,我突然也遇到了同样的问题。

我通过删除app/build目录解决了这个问题,并让gradle新建整个项目。

淳于俊迈
2023-03-14

正确的答案是,您的一些jar文件没有编译。您应该在项目中进入您的build.gradle文件,并查看您的依赖项。

如果您只是导入一些jar文件,您可以尝试删除它们并一次添加一个。这将有助于您确定其中哪一个导致了错误。

在我的例子中,我就是这么做的,当我导入最后一个时,应用程序被编译了。所以我认为真正的问题是我一次进口了太多。但现在一切都好了。

 类似资料: