I am using RxJava3 and retrofit but I am unable to get a rxjava3 retrofit-adapter for RxJava3.
Asked
Active
Viewed 1.5k times
29
-
It seems there is no support yet though you can find a workaround here https://github.com/square/retrofit/issues/3158 – Chetan Gaikwad Mar 10 '20 at 06:04
-
2I've released a fresh adapter version to match RxJava 3.0.0: https://github.com/akarnokd/RxJavaRetrofitAdapter#rxjavaretrofitadapter (I thought Retrofit official will do their version in the meantime, but apparently not.) – akarnokd Mar 10 '20 at 08:34
-
implementation 'com.squareup.retrofit2:adapter-rxjava3:2.9.0' we can use like .addCallAdapterFactory(RxJava3CallAdapterFactory.create()) – Shijen N Sep 26 '20 at 21:27
3 Answers
71
There is now an official Retrofit implementation with version 2.9.0:
Just use the adapter where you create your Retrofit client:
val rxAdapter = RxJava3CallAdapterFactory.create()
retrofit = Retrofit.Builder().baseUrl(baseUrl)
.addConverterFactory(MoshiConverterFactory.create(moshi))
.client(httpClient)
.addCallAdapterFactory(rxAdapter).build()
And include the RxAdapter dependency in your build.gradle
:
implementation 'com.squareup.retrofit2:adapter-rxjava3:2.9.0'
https://github.com/square/retrofit/blob/master/CHANGELOG.md#version-290-2020-05-20
Also from the documentation:
Unlike the RxJava 1 and RxJava 2 adapters, the RxJava 3 adapter's create() method will produce asynchronous HTTP requests by default. For synchronous requests use createSynchronous() and for synchronous on a scheduler use createWithScheduler(..)

devz
- 2,629
- 2
- 31
- 37
6
Use the RxJavaRetrofitAdapter library by @akarnokd.
implementation "com.github.akarnokd:rxjava3-retrofit-adapter:3.0.0"

AdamHurwitz
- 9,758
- 10
- 72
- 134

Vladyslav Berdnikov
- 166
- 1
- 7
0
Use the
implementation 'com.squareup.retrofit2:adapter-rxjava3:2.9.0'

Codemaker2015
- 12,190
- 6
- 97
- 81

kenn_gm
- 11