如何解决java.util.zip.ZipException:重复条目:com / google / gson / Gson $ 5.class?

时间:2016-12-25 15:27:11

标签: android build.gradle retrofit2 gson

我在我的应用中使用 zoom.us sdk和 retrofit2 ,zoom.us sdk使用Gson-2.1.jar,我也使用converter-gson进行改造由于这个我使用Gson-2.8.0构建apk我得到以下错误。

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/gson/Gson$5.class

App build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"
    defaultConfig {
        applicationId "com.android.******"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        // Enabling multidex support.
        multiDexEnabled = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
    }


}


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:appcompat-v7:24.1.0'
    compile 'com.android.support:design:24.1.0'
    testCompile 'junit:junit:4.12'
    compile 'com.jakewharton:butterknife:8.4.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
    compile 'com.android.support:cardview-v7:24.1.0'
    compile project(':zoomcommonlib')
    compile (project(':zoomsdk')){
        transitive = true;
        exclude module: 'gson'
    }
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
}

我还在app build.gradle中添加了以下代码,但没有解决问题。

configurations {
    all*.exclude group: 'com.google.gson', module: 'gson-2.7'
    all*.exclude group: 'com.google.api.client.json.gson', module: 'zoomsdk-unspecified'
    all*.exclude group: 'com.google.gson', module: 'zoomsdk-unspecified'
}

并且

 compile (project(':zoomsdk')){
        exclude group: 'com.google.code.gson';
    }

如何解决此问题?

1 个答案:

答案 0 :(得分:0)

我面临同样的问题因为缩放改造两者都在使用 gson 而且我还尝试使用所有排除方法但没有达到任何解决方案。最后我找到了解决方案:

1 - 删除

    cmp edi, 6 ;Bounds check
    ja  .L2    ;jump to default branch
    mov eax, edi
    jmp [QWORD PTR .L4[0+rax*8]]
.L4:
    .quad   .L2 ;case 0 (same as default!!!)
    .quad   .L3 ;case 1
    .quad   .L5 ;case 2
    .quad   .L6 ;case 3
    .quad   .L7 ;case 4
    .quad   .L8 ;case 5
    .quad   .L9 ;case 6

2-Add

   compile 'com.squareup.retrofit2:converter-gson:2.1.0'

并按照响应模型中的jackson转换程序进行操作。确保模型中有默认构造函数

   compile 'com.squareup.retrofit2:converter-jackson:2.1.0'