使用RxJava2 + Retrofit 报错DuplicateFileException

2017/6/15 更新

如果大家在学习rxjava2.x + retrofit的时候,不要使用上面的依赖了,上面的是rxjava2.x 刚出来的时候没有合适的rxjavaadapter 采用的JW临时方案,现在已经有正式版了


dependencies {
...
  //okhttp
    compile 'com.squareup.okhttp3:okhttp:3.6.0'
    compile 'com.squareup.okio:okio:1.11.0'

  //gson
    compile 'com.google.code.gson:gson:2.8.0'


    //retrofit 网络请求框架
    compile 'com.squareup.retrofit2:retrofit:2.3.0'
    compile 'com.squareup.retrofit2:converter-gson:2.3.0'
    compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'

    //rxjava
    compile 'io.reactivex.rxjava2:rxjava:2.1.0'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
}
复制代码

另外如果依然有报错,可以采用这个同学的方法尝试解决

我喂自己袋丶夏洛克: @看空间疼痛春节前日本剧  报的错是一样的,相当于没有解决,所以我尝试了其他办法,最后在gradle文件中添加 packagingOptions {exclude 'META-INF/rxjava.properties'}后解决了问题,其他朋友若按照此文作者的方法还未能解决问题的话,可以尝试使用我这个方法,能有效解决。


原文。

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/rxjava.properties
	File1: C:\Users\pdog18\.gradle\caches\modules-2\files-2.1\io.reactivex.rxjava2\rxjava\2.0.1\57f850a6b317e5582f1dbaff10a9e7d7e1fcdcfb\rxjava-2.0.1.jar
	File2: C:\Users\pdog18\.gradle\caches\modules-2\files-2.1\io.reactivex\rxjava\1.1.1\b494968f6050d494de55dc3ce005e59c7eb40012\rxjava-1.1.1.jar

复制代码
支持有问题
//compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
复制代码

改用

compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
复制代码
//修改后
dependencies {
...

    compile 'com.squareup.okhttp3:okhttp:3.5.0'
    compile 'com.squareup.okio:okio:1.11.0'

    compile 'com.squareup.retrofit2:retrofit:2.0.2'
    compile 'com.squareup.retrofit2:converter-gson:2.0.2'

//    compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
    compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
    compile 'io.reactivex.rxjava2:rxjava:2.0.1'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'

}
复制代码

转载于:https://juejin.im/post/5a31ee5ef265da43195648a9

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值