2016-12-25 39 views
1

我正在使用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 

應用的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' 
} 

我還添加以下代碼的應用程序的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'; 
    } 

如何解決這個問題?

+0

可能這會幫助你。 http://stackoverflow.com/questions/33209631/errorexecution-failed-for-task-apptransformclasseswithjarmergingfordebug – androgo

+0

沒有工作@androgo –

+0

@NaveenKumar你找到解決方案嗎?我面臨同樣的問題 –

回答

0

我面臨同樣的問題,其原因放大改造兩者都是使用GSON,也是我試圖用一切排除方法,但沒有達成任何solution.Finally我找到了解決辦法:

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() 
{ 
} 
相關問題