如果同时引入以下库
1
2
3
4
implementation 'io.reactivex.rxjava2:rxjava:2.1.3'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.3.0'
就会出现
1
2
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
即使通过以下方式忽略META-INF/rxjava.properties
,重新编译后还会出现Unable to merge dex
错误
1
2
3
packagingOptions {
exclude 'META-INF/rxjava.properties'
}
报错的原因是com.squareup.retrofit2:adapter-rxjava
只能支持Retrofit1
,不支持Retrofit2
,所以只要引入以下的库替代即可:
1
implementation 'com.squareup.retrofit2:adapter-rxjava2:1.0.0'
参考链接:
- http://blog.csdn.net/bingducaijun/article/details/53584449
- http://winkyqin.com/2017/01/21/Android%E5%B8%B8%E8%A7%81%E5%BC%82%E5%B8%B8%E8%A7%A3%E5%86%B3/2017-02-07/