【问题标题】:Error ':app:packageAllDebugClassesForMultiDex'. > java.util.zip.ZipException: duplicate entry:错误“:应用程序:packageAllDebugClassesForMultiDex”。 > java.util.zip.ZipException:重复条目:
【发布时间】:2015-09-14 04:24:49
【问题描述】:

我正在使用 Android Studio 中的 gradle 为家庭自动化开发 android 应用程序。我构建项目时没有问题,但是当我尝试运行项目时,出现这样的错误:

错误:任务 ':app:packageAllDebugClassesForMultiDex' 执行失败。 java.util.zip.ZipException:重复条目:org/apache/http/params/CoreConnectionPNames.class

这是我的 build.gradle 代码:

 apply plugin: 'com.android.application'
    android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.cpl"
        minSdkVersion 15
        targetSdkVersion 23

        multiDexEnabled true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

    dependencies {
    compile 'com.android.support:support-v4:23.0.1'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'com.google.android.gms:play-services:+'
    compile 'com.android.support:appcompat-v7:23.0.1'

    compile files('libs/android.jar')
    compile files('libs/bcprov-jdk15on-1.47.jar')
    //compile files('libs/google-play-services.jar')
    //compile files('libs/google-play-services1.jar')
    compile files('libs/httpclient-4.2.3.jar')
    compile files('libs/httpcore-4.3.jar')
    compile files('libs/nineoldandroids-library-2.4.0.jar')
    compile files('libs/Pubnub-Android-3.7.2.jar')
    compile files('libs/renderscript-v8.jar')
    compile files('libs/sun.misc.BASE64Decoder.jar')
    compile files('libs/universal-image-loader-1.9.2.jar')
    //compile files('libs/android-support-multidex.jar')

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

}

请帮我解决这个问题。还是谢谢你

【问题讨论】:

  • 什么是编译文件('libs/android.jar') 参考
  • 从 build.gradle 文件中移除未使用的库

标签: android gradle android-gradle-plugin android-multidex


【解决方案1】:

请按以下方式更改您的 gradle 依赖项:

compile 'com.android.support:support-v4:23.0.1'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.google.android.gms:play-services:+'
compile 'com.android.support:appcompat-v7:23.0.1'

compile files('libs/renderscript-v8.jar')
compile files('libs/sun.misc.BASE64Decoder.jar')

compile 'org.apache.httpcomponents:httpclient:4.2.3'
compile 'org.bouncycastle:bcprov-jdk15on:1.47'
compile 'org.apache.httpcomponents:httpcore:4.3'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.pubnub:pubnub-android:3.7.2'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.2'
compile 'com.android.support:multidex:1.0.1'

注意

在 Gradle 中,当我们不使用 gradle 依赖并且我们的 libs 文件夹依赖包含重复的类时

java.util.zip.ZipException: duplicate entry

发生此异常。

所以,无论何时添加依赖项,如果可能,请尽量使用 maven 依赖项。

谢谢。!!

【讨论】:

  • 您好 AndiGeeky,您能否详细说明解决方案。我面临着类似的问题。我的库在 libs 文件夹中,它们是自定义库,因此既不在 Maven 也不在 gradle 上。
【解决方案2】:

尝试添加以下依赖项:

  compile 'com.google.android.gms:play-services-plus:8.1.0'
  compile 'com.google.android.gms:play-services-location:8.1.0'
  compile 'com.google.android.gms:play-services-identity:8.1.0'
  compile 'com.google.android.gms:play-services-maps:8.1.0'
  compile 'com.google.android.gms:play-services-gcm:8.1.0'
  compile 'com.google.android.gms:play-services-appindexing:8.1.0'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-25
    • 1970-01-01
    • 1970-01-01
    • 2016-07-09
    • 2017-08-18
    相关资源
    最近更新 更多