我在项目中使用RxJava1和Retrofit2。大约10%的用户收到以下错误:
Caused by java.lang.IllegalArgumentException: Could not locate call
adapter for rx.Single<com.squareup.okhttp.ResponseBody>.
Tried:
* retrofit2.adapter.rxjava.RxJavaCallAdapterFactory
* retrofit2.ExecutorCallAdapterFactory
at retrofit2.Retrofit.nextCallAdapter(Retrofit.java:237)
at retrofit2.Retrofit.callAdapter(Retrofit.java:201)
at retrofit2.ServiceMethod$Builder.createCallAdapter(ServiceMethod.java:232)
at
retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:160)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:166)
at retrofit2.Retrofit$1.invoke(Retrofit.java:145)
at java.lang.reflect.Proxy.invoke(Proxy.java:913)
...
相关的代码段如下:
import rx.Single
val retrofit = Retrofit.Builder()
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.baseUrl(BuildConfig.API_BASE_URL)
.build()
@FormUrlEncoded
@POST("/example")
fun exampleFun(@Field("param") param1: String): Single<ResponseBody>
implementation 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
我已经发现了类似的问题,但这不是同一个问题。
RxJava2CallAdapterFactory
RxJavaCallAdapterFactory
,但我使用的是RxJava1。