Android:build.gradle中的重复条目

时间:2015-10-20 20:07:51

标签: android gradle

我尝试使用Android Studio运行我的Android应用程序,并显示错误说明以下消息。

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.transform.api.TransformException: java.util.zip.ZipException: duplicate entry: com/mikepenz/iconics/core/BuildConfig.class

似乎有一个重复的库,这就是它停止运行的原因。但老实说,我不知道应该使用build.gradle文件修复哪些内容。所以我把build.gradle文件放在这里,有人请帮帮我。

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

//wrap with try and catch so the build is working even if the signing stuff is missing
try {
    apply from: '../../../signing.gradle'
} catch (ex) {
}

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

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

        applicationVariants.all { variant ->
            variant.outputs.each { output ->
                def file = output.outputFile
                def fileName = file.name.replace(".apk", "-v" + versionName + "-c" + versionCode + ".apk")
                output.outputFile = new File(file.parentFile, fileName)
            }
        }
    }
    buildTypes {
        debug {
            applicationIdSuffix ".debug"
            versionNameSuffix "-DEBUG"
            try {
                signingConfig signingConfigs.debug
            } catch (ex) {
            }
            minifyEnabled false
        }
        release {
            try {
                signingConfig signingConfigs.release
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            } catch (ex) {
            }
            zipAlignEnabled true
            minifyEnabled false
        }
    }
    lintOptions {
        abortOnError false
    }
}

repositories() {
    mavenCentral()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:support-v13:23.1.0'
    compile 'com.squareup.okhttp:okhttp:2.0.0'
    compile 'com.android.support:support-v4:23.1.0'
    compile 'com.android.support:design:23.1.0'
    compile 'com.squareup.picasso:picasso:2.3.2'

    // Google Analytics Library
    compile 'com.google.android.gms:play-services-analytics:8.1.0'
    compile 'com.google.android.gms:play-services:8.1.0'

    // Glide Library
    compile 'com.github.bumptech.glide:glide:3.6.1'

    // Material Drawer Library by Mike Penz
    compile('com.mikepenz:materialdrawer:4.3.8@aar') {
        transitive = true
    }

    // Android Iconics Library by Mike Penz
    compile 'com.mikepenz:iconics-core:1.7.9@aar'
    compile 'com.mikepenz:google-material-typeface:1.2.0.1@aar'

    // Circle image view library
    compile 'de.hdodenhof:circleimageview:2.0.0'

    // AboutLibraries by Mike Penz
    compile('com.mikepenz:aboutlibraries:5.2.5@aar') {
        transitive = true
    }
}

1 个答案:

答案 0 :(得分:0)

您的依赖项存在冲突。

duplicate entry: com/mikepenz/iconics/core/BuildConfig.class

这意味着您的两个依赖项包含此类

// Android Iconics Library by Mike Penz
compile 'com.mikepenz:iconics-core:1.7.9@aar'
compile 'com.mikepenz:google-material-typeface:1.2.0.1@aar'

// AboutLibraries by Mike Penz
compile('com.mikepenz:aboutlibraries:5.2.5@aar') {
    transitive = true // <- Why?
}

我的猜测是要么不应该指定transitive,要么其中一个com.mikepenz库实际上包含其他一个库。例如,如果iconics-core中包含aboutlibraries,那么您应该通过

将其排除
compile('com.mikepenz:aboutlibraries:5.2.5@aar') {
    exclude module: 'com.mikepenz', name: 'iconics-core'
}

通过dependencies运行gradle任务gradle dependencies来轻松追踪依赖性问题的方法。这显示了一个很好的libs图表依赖于其他库