* What went wrong:
Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> More than one file was found with OS independent path 'META-INF/rxjava.properties'复制代码
前几天在首次使用Retrofit和RxJava报错,当时一直没有找到解决方案,而且网上百度的方案也没法解决。java
后来无心中看到大佬写的一篇文章才得以解决该错误。对应文章(文中4.3步骤实现有介绍):react
参看这篇文章后,再回看本身的build.gradle
,才知道对应的错误在哪儿android
原来是这样写的:bash
//支持Gson解析
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
//添加RxJava
implementation 'io.reactivex.rxjava2:rxjava:2.2.14'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'复制代码
错误就在这个库“implementation 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
”,该库时对应于retrofit2
与RxJava
,而不是RxJava2
。网络
仅仅是这个错误才致使上述报错的缘由,app
附上正确的库:工具
//retrofit开源的网络请求工具
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
//添加RxJava
implementation 'io.reactivex.rxjava2:rxjava:2.2.14'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
//衔接Retrofit 和 RxJava
//此处必定要注意使用RxJava2的版本
implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
//支持Gson解析
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.google.code.gson:gson:2.8.5'
复制代码