【问题标题】:How to resolve java.util.zip.ZipException: duplicate entry: com/google/gson/Gson$5.class?如何解决 java.util.zip.ZipException:重复条目:com/google/gson/Gson$5.class?
【发布时间】:2016-12-25 15:27:10
【问题描述】:

我在我的应用程序中使用 zoom.us sdk 和 retrofit2,zoom.us sdk 使用 Gson-2.1.jar,我还使用 converter-gson 进行改造由于这个原因,当我构建 apk 时使用 Gson-2.8.0,我在下面遇到错误。

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

应用构建.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';
    }

如何解决这个问题?

【问题讨论】:

标签: android build.gradle retrofit2 gson


【解决方案1】:

我遇到了同样的问题,因为 ZoomRetrofit 都在使用 gson 并且我尝试使用所有 exclude strong> 方法,但没有找到任何解决方案。最后我找到了解决方案:

1-删除

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

2-添加

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

并在您的响应模型中遵循杰克逊转换器流程。确保模型中有默认构造函数

@JsonIgnoreProperties(ignoreUnknown=true)
public class User
{
@JsonProperty("id")
public int id;
@JsonProperty("username")
public String username;
@JsonProperty("first_name")
public String first_name;
@JsonProperty("email")
public String email;
@JsonProperty("last_name")
public String last_name;
@JsonProperty("gender")
public String gender;
@JsonProperty("profile_image_path")
public String profile_image_path;

  // must implement default constructor 
public User()
{
}

【讨论】:

    猜你喜欢
    • 2017-03-07
    • 1970-01-01
    • 1970-01-01
    • 2012-06-01
    • 1970-01-01
    • 2017-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多