我们应该为 Rxjava3 使用哪个 rxjava3 retrofit-adapter

Which rxjava3 retrofit-adapter should we use for Rxjava3

我正在使用 RxJava3 和改造,但我无法获得用于 RxJava3 的 rxjava3 改造适配器。

使用 RxJavaRetrofitAdapter@akarnokd

implementation "com.github.akarnokd:rxjava3-retrofit-adapter:3.0.0"

现在有 2.9.0 版的官方 Retrofit 实现:

只需使用创建 Retrofit 客户端的适配器:

val rxAdapter = RxJava3CallAdapterFactory.create()
retrofit = Retrofit.Builder().baseUrl(baseUrl)
            .addConverterFactory(MoshiConverterFactory.create(moshi))
            .client(httpClient)
            .addCallAdapterFactory(rxAdapter).build()

并在您的 build.gradle:

中包含 RxAdapter 依赖项
implementation 'com.squareup.retrofit2:adapter-rxjava3:2.9.0'

https://github.com/square/retrofit/blob/master/CHANGELOG.md#version-290-2020-05-20

也来自文档:

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(..)

使用

implementation 'com.squareup.retrofit2:adapter-rxjava3:2.9.0'