【问题标题】:Android studio multi dex error while executing packageAllDebugClassesForMultiDex task执行 packageAllDebugClassesForMultiDex 任务时 Android Studio 多 dex 错误
【发布时间】:2025-11-24 17:35:02
【问题描述】:

我正在为我的项目实施多 dex。我能够在实现 multidex 之后编译代码,但是在运行项目时,我在执行 packageAllDebugClassesForMultiDex 任务时遇到下面提到的错误。 错误:任务 ':appname:packageAllDebugClassesForMultiDex' 执行失败。

java.util.zip.ZipException:重复条目:android/support/multidex/MultiDex.class

依赖列表:-

dependencies {
    compile project(':slidingMenu')
    compile project(':androidPullToRefresh')
    compile project(':googlePlayServices')
    compile project(':caldroid')
    compile files('libs/admsAppLibrary.jar')
    compile files('libs/gson-2.3.1.jar')
    compile files('libs/jackson-annotations-2.1.1.jar')
    compile files('libs/jackson-core-2.1.1.jar')
    compile files('libs/jackson-databind-2.1.1.jar')
    compile files('libs/jsr305-1.3.9.jar')
    compile files('libs/okhttp-2.2.0.jar')
    compile files('libs/retrofit-1.9.0.jar')
    compile files('libs/xtify-android-sdk-2.4.jar')
    compile project(':clusterkraf')
    compile files('libs/okio-1.0.0.jar')
    compile files('libs/android-support-multidex.jar')
}

下面是我的项目结构。

库 A 包含我的应用程序类。我在其中实现了multidex。 库 B 和库 C 依赖于库 A 我的启动项目 D 依赖于库 B 和库 C。库 D android 清单我已经定义了库 A 中可用的应用程序类。

【问题讨论】:

  • 请显示 logcat 以确定错误
  • @Aspicas 没有 logcat 日志,因为它是编译时错误 ...
  • 是的,但它总是报告 logcat
  • 错误很明显...android-support-multidex.jar被多次使用...请在询问之前做一些研究
  • @Selvin 我知道错误,但我需要知道哪个库有问题才能给他/她一个好的解决方案。

标签: android android-studio build.gradle android-build android-multidex


【解决方案1】:

如果要在 build.gradle 中添加播放服务库,请在依赖项中添加 compile 'com.google.android.gms:play-services:7.5.0'

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.google.android.gms:play-services:7.5.0'
}

如果有冲突添加

  android {
        compileSdkVersion 22
        buildToolsVersion "22.0.1"
.....

    dexOptions {
            preDexLibraries = false
        }
.....
}

在 android 块中

【讨论】:

  • 由于防火墙问题,我将无法使用 maven。所有依赖项都是本地的。 preDexLibraries 选项没有帮助。 :(
  • @HariSoni 据我了解,您已经实现了多个依赖项,您已经添加了 A -> B & C 和 B & C ->D 的依赖项,这造成了问题
  • 如果可能的话,使用 A -> B , B->C C->D 可以顺利运行并在主项目中声明所有库,或者我的意思是主应用程序
  • 这是一个旧代码库,代码紧密耦合,因为改变项目结构将是一项具有挑战性的任务。为什么我的其他图书馆没有发生这种情况?我有大约 8 个图书馆。
  • :) 保留您的项目的备份,然后尝试我在评论中提到的内容,我猜它不会产生问题,因为 A 库的依赖项将通过 B 库提供给 C
最近更新 更多