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'
}
复制代码