Unable to create call adapter for io.reactivex.Observable

夙愿已清 提交于 2019-12-02 19:52:59

You need to tell Retrofit that you want to use RxJava 2, using:

addCallAdapterFactory(RxJava2CallAdapterFactory.create())

So, for creating your Retrofit object, you will have something like:

Retrofit retrofit = new Retrofit.Builder()
    .baseUrl(SERVICE_ENDPOINT)
    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
    .build();
Raut Darpan

I ran into the same issue. Instead of adding new repositories you can add the dependency of Jake Wharton's library:

implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'

Then you can add factory:

Retrofit retrofit = new Retrofit.Builder()
    .baseUrl("https://api.example.com")
    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
    .build();

The fact that adapter has version 2.. does not mean that it is intended for use with RxJava 2, as I thought.

implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'

The problem is with the library being used.

I have replaced

implementation 'com.squareup.retrofit2:adapter-rxjava:2.4.0'

with

implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'

and used

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