Gradle构建错误:重复条目

时间:2016-04-28 09:52:43

标签: android gradle android-gradle build.gradle android-spinner

我的gradle文件是

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "24.0.0 rc2"

defaultConfig {
    applicationId "com.test.test"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

buildscript {
repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    classpath 'com.android.tools.build:gradle:2.1.0'
    classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
}
}

repositories {
mavenCentral()
jcenter()
flatDir {
    dirs '../libs'
}
}



dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.3.0'
compile('com.google.android.gms:play-services:8.4.0') {
    exclude group: 'com.google.guava'
}
compile ('org.apache.httpcomponents:httpcore:4.4.4')
        {
            exclude group: 'org.apache.http.annotation.NotThreadSafe'
        }
compile 'commons-io:commons-io:2.4'
compile 'com.android.support:support-annotations:23.0.0'
compile 'com.android.support:recyclerview-v7:23.0.0'
compile 'com.google.android.exoplayer:exoplayer:r1.4.2'
compile 'com.mopub.volley:mopub-volley:1.1.0'
compile 'com.android.support:multidex:1.0.0'
}

编译应用程序时出现此错误

错误:任务执行失败':myapplication:transformClassesWithJarMergingForDebug'。  com.android.build.api.transform.TransformException: java.util.zip.ZipException:重复条目:org / apache / http / annotation / NotThreadSafe.class

任何人都可以告诉我需要从依赖项列表中排除的内容。或问题的任何解决方案?

3 个答案:

答案 0 :(得分:0)

如果您包含其他子项目,请务必小心。您可以通过在“ proguard-rules.pro ”中添加以下异常来解决此问题:

-dontwarn org.apache.**

答案 1 :(得分:0)

像这样修改你的gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "24.0.0 rc2"

defaultConfig {
    applicationId "com.test.test"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}

packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/notice.txt'
}

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

buildscript {
repositories {
    mavenCentral()
    jcenter()
}

dependencies {
    classpath 'com.android.tools.build:gradle:2.1.0'
    classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
}
}

repositories {
mavenCentral()
jcenter()
flatDir {
    dirs '../libs'
}
}



dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.3.0'
compile('com.google.android.gms:play-services:8.4.0') {
    exclude group: 'com.google.guava'
}
compile ('org.apache.httpcomponents:httpcore:4.4.4')
        {
            exclude group: 'org.apache.http.annotation.NotThreadSafe'
        }
compile 'commons-io:commons-io:2.4'
compile 'com.android.support:support-annotations:23.0.0'
compile 'com.android.support:recyclerview-v7:23.0.0'
compile 'com.google.android.exoplayer:exoplayer:r1.4.2'
compile 'com.mopub.volley:mopub-volley:1.1.0'
compile 'com.android.support:multidex:1.0.0'
}

packagingOptions将允许您使用重复的类。这意味着如果两个具有相同类名的库,那么编译器将忽略它。

答案 2 :(得分:-1)

清理项目,然后再次构建.duplicate条目错误将解决。