Could not locate call adapter for io.reactivex.rxjava3.core.ai<...> Tried: * retrofit2.adapter.rx...

升级rxjava2到rxjava3以后,由于没有升级adapter-rxjava2到adapter-rxjava3 导致报如下错误:

java.lang.IllegalArgumentException
Could not locate call adapter for io.reactivex.rxjava3.core.ai>. Tried: * retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory * retrofit2.ExecutorCallAdapterFactory
******************************************************************************
1 java.lang.RuntimeException:Unable to start activity ComponentInfo{com.ume.browser/com.ume.sumebrowser.activity.book.ReadNovelActivity}: java.lang.IllegalArgumentException: Unable to create call adapter for io.reactivex.rxjava3.core.ai>
2 for method RestInterface.getBookDetail
3 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3568)
4 ......
5 Caused by:
6 java.lang.IllegalArgumentException:Could not locate call adapter for io.reactivex.rxjava3.core.ai>.
7 Tried:
8 * retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
9 * retrofit2.ExecutorCallAdapterFactory
10 retrofit2.Retrofit.nextCallAdapter(Retrofit.java:241)
11 retrofit2.Retrofit.callAdapter(Retrofit.java:205)
12 retrofit2.ServiceMethod$Builder.createCallAdapter(ServiceMethod.java:235)
13 retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:162)
14 retrofit2.Retrofit.loadServiceMethod(Retrofit.java:170)
15 retrofit2.Retrofit$1.invoke(Retrofit.java:147)
16 java.lang.reflect.Proxy.invoke(Proxy.java:1006)
17 $Proxy4.getBookDetail(Unknown Source)
18 com.ume.sumebrowser.activity.book.b.a.a(ReadNovelModel.java:248)
19 com.ume.sumebrowser.activity.book.b.b(ReadNovelPresenter.java:134)
20 com.ume.sumebrowser.activity.book.ReadNovelActivity.n(ReadNovelActivity.java:567)
21 com.ume.sumebrowser.activity.book.ReadNovelActivity.onCreate(ReadNovelActivity.java:223)
22 android.app.Activity.performCreate(Activity.java:8064)
23 android.app.Activity.performCreate(Activity.java:8048)
24 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1310)
25 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3541)
26 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3720)
27 android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
28 android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
29 android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
30 android.app.ActivityThread$H.handleMessage(ActivityThread.java:2163)
31 android.os.Handler.dispatchMessage(Handler.java:106)
32 android.os.Looper.loop(Looper.java:243)
33 android.app.ActivityThread.main(ActivityThread.java:7934)
34 java.lang.reflect.Method.invoke(Native Method)
35 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
36 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:952)
解决办法

出现这样的错误就将adapter-rxjava2升级到3就好了。

引用
 implementation "com.squareup.retrofit2:adapter-rxjava3:2.9.0"
工程中的修改
Retrofit.Builder builder = new Retrofit.Builder()
                .baseUrl(API_BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava3CallAdapterFactory.create());// 这里换成RxJava3CallAdapterFactory.create()

你可能感兴趣的:(Could not locate call adapter for io.reactivex.rxjava3.core.ai<...> Tried: * retrofit2.adapter.rx...)