2017-08-30 63 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