RxJavaCallAdapterFactory cannot be converted to Factory

北战南征 提交于 2019-12-04 23:31:32

Make sure you are using the same groupId and version for the main Retrofit dependency, the Gson converter dependency, and the RxJava adapter dependency.

I'm guessing yours look something like this:

compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta2'

(Note that they use different groupIds and version numbers)

They should all look the same like this:

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'

Currently adding "com.squareup.retrofit:adapter-rxjava:2.0.0" gives following error

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

But, instead, adding "compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0",makes packaging successful

change your retrofit rxjava adapter into

  implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"

And change your CallAdapterFactory into

.addCallAdapterFactory(RxJava2CallAdapterFactory.create())

it will look something like this

.baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!