例外:重复条目:android / support / v7 / widget / CardViewApi21.class

时间:2016-09-28 08:39:25

标签: android android-studio gradle android-gradle

您好我正面临此错误

Error:Execution failed for task transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v7/widget/CardViewApi21.class

我删除重复的依赖项,lib。

gradle这个

apply plugin: 'com.android.application'

 dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
//compile 'com.android.support:cardview-v7:21.0.3'
compile ('com.android.support:cardview-v7:21.0.3') {
    exclude module: 'support-v4'
}
compile project(':FacebookSDK')
compile 'com.android.support:multidex:1.0.1'

compile project(':google-play-services_lib')
//compile files('libs/cardview-v7-21.0.0.jar')
 }

android {
compileSdkVersion 16
buildToolsVersion "23.0.2"
repositories {
    mavenCentral()
}
signingConfigs {
    release {
        storeFile file("demo.jks")
        storePassword "demo"
        keyAlias "demo"
        keyPassword "demo"
    }
}

dexOptions {
    //incremental = true;
    preDexLibraries = false
    javaMaxHeapSize "4g"
}

buildTypes {
    release {
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release
        lintOptions {
            disable 'MissingTranslation'
        }
    }
}
lintOptions {
    abortOnError false
    checkReleaseBuilds false
}
packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/ASL2.0'
}

defaultConfig {
    multiDexEnabled true
}

sourceSets {
    main {
        manifest.srcFile 'AndroidManifest.xml'
        java.srcDirs = ['src']
        resources.srcDirs = ['src']
        aidl.srcDirs = ['src']
        renderscript.srcDirs = ['src']
        res.srcDirs = ['res']
        assets.srcDirs = ['assets']
    }

    // Move the tests to tests/java, tests/res, etc...
    instrumentTest.setRoot('tests')

    // Move the build types to build-types/<type>
    // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
    // This moves them out of them default location under src/<type>/... which would
    // conflict with src/ being used by the main source set.
    // Adding new build types or product flavors should be accompanied
    // by a similar customization.
    debug.setRoot('build-types/debug')
    release.setRoot('build-types/release')
  }
  }
 apply plugin: 'announce'

3 个答案:

答案 0 :(得分:0)

尝试像那样编译你的cardview

Column
#1 747, 757, 767
#2 747, 757
#3 767, 777
...

答案 1 :(得分:0)

从lib文件夹中删除未使用的jar。 清理项目并尝试重新编译。

还将compileToolVersion设置为23。

答案 2 :(得分:0)

似乎有一个名为cardview-v7-21.0.0.jar的jar文件。

评论

//compile files('libs/cardview-v7-21.0.0.jar').

但使用此行

compile fileTree(dir: 'libs', include: '*.jar')

你只是包含相同的jar文件。

应该从cardview-v7-21.0.0.jar文件夹中删除 libs文件。