Reputation: 3187
My Api:
@GET("/cinema/notShownMovies")
fun getNotShownMovies(
@Query("token") token: String
): Response<GetMovieResponse>
Exception when trying to call 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
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?
Upvotes: 26
Views: 20700
Reputation: 11683
I had a similar crash 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 was renaming Retrofit classes and to fix it I updated the Proguard settings with:
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
Upvotes: 17
Reputation: 1
In the Gradle file add this line inside of release buildTyps
Upvotes: -7
Reputation: 1674
Just add suspend
modifier if using coroutines
. This will solve the problem.
Otherwise your issue is likely because there is no Call adapter added when instantiating your Retrofit
object.
For example, for RxJava2
, you can include a call adapter by adding this line while building it.
.addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
Upvotes: 68