【问题标题】:Duplicate entry error by using Gson with Retrofit使用 Gson 和 Retrofit 重复输入错误
【发布时间】:2017-08-30 07:43:29
【问题描述】:

我正在使用改造,rxjavagson 进行 api 通话。我在构建或清理应用程序时没有收到任何错误,但只要我在设备中运行应用程序;我收到错误,即

**错误:任务 ':app:transformClassesWithJarMergingForDebug' 执行失败。

com.android.build.api.transform.TransformException:java.util.zip.ZipException:重复条目:com/google/gson/annotations/Expose.class**

依赖文件 app 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'


}

注意:我已经尝试过 stackoverflow 中给出的许多解决方案,例如从改造中排除 gson 等等。 请帮助提前谢谢。

【问题讨论】:

  • 您是否尝试从改造中排除“gson”依赖项?
  • 是的,我已经试过了
  • 尝试删除 Multidex 并重建项目
  • 并检查您的 lib 文件夹是否有任何 gson jar 文件。如果存在则删除它
  • 您向我们隐藏的是“libs”,它可能有 gson jar,与“com.squareup.retrofit2:converter-gson:2.1.0”冲突

标签: java android retrofit2 rx-java2 gson


【解决方案1】:

这对我有用:

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'

尝试使用如上所示的依赖项

【讨论】:

  • 尝试使缓存无效并重新启动。如果不起作用,请显示您的完整 build.gradle。另外,删除所有包装选项,没有它们对我有用
【解决方案2】:

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'
}

【讨论】:

  • 我必须在哪里包括这个?应用程序级别或项目级别?
  • 已经在build.gradle文件(应用级别)中提到过
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-01-07
  • 2021-11-20
  • 1970-01-01
  • 2014-12-28
  • 2019-12-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多