2017-08-30 60 views
0

我正在使用改造,rxjavagsonapi調用。在構建或清理應用程序時,我沒有收到任何錯誤,但只要我在設備中運行應用程序;我得到錯誤,即通過使用Gson與Retrofit重複輸入錯誤

**錯誤:任務':app:transformClassesWithJarMergingForDebug'的執行失敗。

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/gson/annotations/Expose.class**

depedencies文件應用的build.gradle是:

dependencies { 

    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:appcompat-v7:24.0.0' 
    compile 'com.android.support:design:24.0.0' 
    compile 'com.android.support:cardview-v7:24.0.0' 
    compile 'com.google.android.gms:play-services-location:8.4.0' 
    compile 'com.google.android.gms:play-services-gcm:8.4.0' 

    compile 'com.android.support:multidex:1.0.1' 

    compile 'com.android.billingclient:billing:dp-1' 

    compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0' 
    compile 'com.squareup.retrofit2:converter-gson:2.1.0' 
    compile 'com.squareup.retrofit2:retrofit:2.1.0' 
    compile 'io.reactivex:rxandroid:1.2.0' 
    compile 'io.reactivex:rxjava:1.1.8' 


} 

注:我已經嘗試了計算器給出像改造及所有除GSON許多解決方案。 請提前幫助感謝。

+0

你嘗試從改造排除 'GSON' 的依賴? –

+0

是的,我試過那個已經 –

+0

嘗試刪除Multidex和重建項目 –

回答

-1

使用下面的代碼build.gradle(在應用程序級別buildType代碼後)文件並重新生成項目;

packagingOptions { 
    exclude 'META-INF/NOTICE' // will not include NOTICE file 
    exclude 'META-INF/LICENSE' // will not include LICENSE file 
    exclude 'META-INF/DEPENDENCIES' // will not include LICENSE file 
    exclude 'META-INF/LICENSE.txt' 
    exclude 'META-INF/NOTICE.txt' 
} 
+0

,我必須包含這個?應用程序級別或項目級別? –

+0

它已經被提及,即在'build.gradle'文件(應用程序級別) – Mandy8055

+0

在buildTypes代碼 –

0

這個工作對我來說:

compile 'com.google.code.gson:gson:2.7' 
compile 'com.squareup.retrofit2:retrofit:2.1.0' 
compile 'com.squareup.retrofit2:converter-gson:2.1.0' 
compile 'io.reactivex.rxjava2:rxjava:2.0.2' 
compile 'io.reactivex.rxjava2:rxandroid:2.0.1' 
compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0' 

嘗試使用依賴如上圖所示

+0

不工作得到相同的錯誤 –

+0

嘗試使緩存失效並重新啓動。如果不工作,請顯示完整的build.gradle。此外,刪除任何packagingOptions,它沒有他們的作品 – user1209216