Gradle Duplicate Entry

2020-02-14 04:38发布

问题:

I integrated the Digits mobile sdk into my project and it wouldn't build anymore. It has some kind of a clash with gson library that i am using. I get this error during the build:

Error:Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: com/google/gson/Gson$5.class

this is my build.gradle

buildscript {
    repositories {maven { url 'https://maven.fabric.io/public' }}
    dependencies {classpath 'io.fabric.tools:gradle:1.+'}}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
    compileSdkVersion 22
    buildToolsVersion "22.0.0"
    defaultConfig {...}
    buildTypes {release {...}}
    dexOptions {preDexLibraries = false
    incremental true
    javaMaxHeapSize "4g"}
    packagingOptions {...}}
repositories {
    mavenCentral()
    maven { url 'https://maven.fabric.io/public' }}
dependencies {
    ...
    compile('com.crashlytics.sdk.android:crashlytics:2.2.4@aar') {
        transitive = true;}
    compile 'io.branch.sdk.android:library:1.5.5'
    compile('com.digits.sdk.android:digits:1.5.0@aar') {
        transitive = true;}}

回答1:

this is the solution

compile('com.digits.sdk.android:digits:1.5.0@aar') {
    transitive = true;
    exclude module: 'gson';
}

you need to add exclude module: 'gson'