android - 错误 ':app:packageAllDebugClassesForMultiDex'。 > java.util.zip.ZipException : duplicate entry:

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

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

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 文件夹依赖项包含重复的类时

java.util.zip.ZipException: duplicate entry

出现此异常。

因此,每当您添加依赖项时,如果可能,请尝试最大程度地使用 Maven 依赖项。

谢谢。!!

关于android - 错误 ':app:packageAllDebugClassesForMultiDex'。 > java.util.zip.ZipException : duplicate entry:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32557291/

相关文章:

android - 任务 ':android:lint'的执行失败无法初始化类com.sun.imageio.plugins.jpeg.JPEGImageReader

gradle - buildscript 和 build.gradle 中的 allprojects 有什么区别?

android - 如何使用两个 Firestore 集合制作一个 ArrayList?

android - React Native + Expo - 触发 android Intent 打开本地存储的文件。 (安卓)

spring-boot - 使用JMeter进行RabbitMQ应用程序负载测试的后端Spring引导

android - 错误:将字节码转换为dex时出错:原因:com.android.dex.DexException:多个dex文件定义了Lcom/example/admin/myapplication/MainActivity;

android - 移动必需品的 Web 服务

java - Wakelock - 标记名称应使用唯一前缀后跟冒号

java - ./gradlew 因 NoSuchAlgorithmException 失败

android - 构建 Android 项目时出错。 "AAPT process not ready to receive commands"