[英]Unable to create call adapter for retrofit2.Response<...>
My Api:我的 Api:
@GET("/cinema/notShownMovies")
fun getNotShownMovies(
@Query("token") token: String
): Response<GetMovieResponse>
Exception when trying to call API:尝试拨打 API 时出现异常:
java.lang.IllegalArgumentException: Unable to create call adapter for retrofit2.Response<...data.GetMovieResponse> for method InstanceApi.getNotShownMovies Unable to create call adapter for retrofit2.Response<...data.GetMovieResponse> for method InstanceApi.getNotShownMovies
java.lang.IllegalArgumentException:无法为 Retrofit2.Response<...data.GetMovieResponse> 方法 InstanceApi.getNotShownMovies 创建调用适配器
I don't know where to start.我不知道从哪里开始。 All other API calls work fine which is also defined in the same API class. Maybe a model error?
所有其他 API 调用工作正常,它也在同一个 API class 中定义。也许是 model 错误?
Just add suspend
modifier if using coroutines
.如果使用
coroutines
只需添加suspend
修饰符。 This will solve the problem.这将解决问题。
Otherwise your issue is likely because there is no Call adapter added when instantiating your Retrofit
object.否则您的问题很可能是因为在实例化
Retrofit
object 时没有添加呼叫适配器。 For example, for RxJava2
, you can include a call adapter by adding this line while building it.例如,对于
RxJava2
,您可以通过在构建时添加此行来包含调用适配器。
.addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
In the Gradle file add this line inside of release buildTyps在 Gradle 文件中,在 release buildTyps 中添加这一行
I had a similar crash IllegalArgumentException: Call return type must be parameterized as Call
.我有一个类似的崩溃
IllegalArgumentException: Call return type must be parameterized as Call
。
Crash log:崩溃日志:
Caused by: java.lang.IllegalArgumentException: Unable to create call adapter for interface retrofit2.Call
for method Api.login
at retrofit2.Utils.methodError(Utils.java:54)
at retrofit2.HttpServiceMethod.createCallAdapter(HttpServiceMethod.java:116)
at retrofit2.HttpServiceMethod.parseAnnotations(HttpServiceMethod.java:67)
at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:39)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:202)
at retrofit2.Retrofit$1.invoke(Retrofit.java:160)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy0.login(Unknown Source)
at <redacted>.screen.login.LoginActivity.onSignInClick(LoginActivity.java:103)
... 13 more
Caused by: java.lang.IllegalArgumentException: Call return type must be parameterized as Call<Foo> or Call<? extends Foo>
at retrofit2.DefaultCallAdapterFactory.get(DefaultCallAdapterFactory.java:42)
at retrofit2.Retrofit.nextCallAdapter(Retrofit.java:253)
at retrofit2.Retrofit.callAdapter(Retrofit.java:237)
at retrofit2.HttpServiceMethod.createCallAdapter(HttpServiceMethod.java:114)
... 20 more
I found out it was crashing because of Proguard/R8.我发现它因为 Proguard/R8 而崩溃。 Proguard was renaming Retrofit classes and to fix it I updated the Proguard settings with:
Proguard 正在重命名 Retrofit 类并修复它我更新了 Proguard 设置:
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.