错误“:应用程序:packageAllDebugClassesForMultiDex”。 > java.util.zip.ZipException:重复条目:

Error ':app:packageAllDebugClassesForMultiDex'. > java.util.zip.ZipException: duplicate entry:

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

Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'. java.util.zip.ZipException: duplicate entry: 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'

}

请帮我解决这个问题。无论如何谢谢你

请更改您的 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 文件夹依赖项包含重复的 class 则

java.util.zip.ZipException: duplicate entry

发生此异常。

因此,无论何时添加依赖项,如果可能,请尽量使用 Maven 依赖项。

谢谢.!!

尝试添加以下依赖项:

  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'