19

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?

kaulex
  • 2,921
  • 3
  • 11
  • 38

3 Answers3

54

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()))
Abdul Mateen
  • 1,418
  • 1
  • 14
  • 32
12

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.** { *; }
ricardopereira
  • 11,118
  • 5
  • 63
  • 81
  • It did solve the problem for crashing, but I am started facing problem adapters. For example I see same item getting displayed multiple times. – Arpit Jun 23 '23 at 14:19
  • It solved :) When I updated my app last December than I haven't faced this issue that time. Today I need to add 2 Progard Rules. Don't know why? – M DEV Jul 27 '23 at 15:58
  • @Arpit I get the same issue of items being displayed multiple times. How did you fix? – Dayem Saeed Aug 08 '23 at 00:46
  • 1
    There are some proguard rules need to define for gson @DayemSaeed please check that – Arpit Aug 10 '23 at 08:19
  • 1
    My `proguard-rules` file had retrofit rules but without the `2` and your comment saved my life Such a little detail brought me so much trouble... – Ícaro Aug 29 '23 at 17:59
-3

In the Gradle file add this line inside of release buildTyps

  • minifyEnabled false
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – abdo Salm Sep 26 '22 at 19:10