Reputation: 551
Below are the Dependencies which I have used
implementation 'com.squareup.retrofit2:retrofit:2.0.2'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
Below is the code which I am calling retrofit API
RequestBody jsonBody = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"),(jsonInput));
RetrofitAPI cashMemoService = RetrofitAPICLient.getClient().create(RetrofitAPI.class);
Call<List<CashMemoDetails>> call = cashMemoService.getCashMemoPendingListObj(jsonBody);
This is RetrofitAPICLient
public static Retrofit getClient(){
if(retrofit == null){
retrofit = new Retrofit.Builder()
.baseUrl(newBseURL)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
Below is the Interface
@POST("GetCashMemoPunchingList")
Call<List<CashMemoDetails>> getCashMemoPendingListObj(@Body RequestBody userData);
Below is the exception which I am getting
2020-10-20 10:59:47.320 27155-27155/ W/com.hpcl.gsa2: Accessing hidden method Ldalvik/system/CloseGuard;->warnIfOpen()V (greylist,core-platform-api, reflection, allowed)
2020-10-20 10:59:47.335 27155-27155/ W/System.err: java.lang.IllegalArgumentException: Unable to create call adapter for interface g.g
55-27155/ W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
2020-10-20 10:59:47.336 27155-27155/ W/System.err: Caused by: java.lang.IllegalArgumentException: Call return type must be parameterized as Call<Foo> or Call<? extends Foo>
2020-10-20 10:59:47.336 27155-27155/ W/System.err: ... 22 more
Please help me on this.Thanks in advance
Upvotes: 17
Views: 6729
Reputation: 1451
This is happening because R8 is running in fullmode. For now you can disable it by setting below flag in gradle.properties:
android.enableR8.fullMode=false
Upvotes: -2
Reputation: 61
I had this error too. Everything worked fine except signed APK's with enabled minify.I have fixed it by adding some rules to the proguard-rules.pro file. In general, for retrofit, you need to add the following rules to proguard-rules.pro:
-keepattributes Signature, InnerClasses, EnclosingMethod
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations
-keepattributes AnnotationDefault
-keepclassmembers,allowshrinking,allowobfuscation interface * {
@retrofit2.http.* <methods>;
}
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn javax.annotation.**
-dontwarn kotlin.Unit
-dontwarn retrofit2.KotlinExtensions
-dontwarn retrofit2.KotlinExtensions$*
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface <1>
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface * extends <1>
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
-if interface * { @retrofit2.http.* public *** *(...); }
-keep,allowoptimization,allowshrinking,allowobfuscation class <3>
-keep,allowobfuscation,allowshrinking class retrofit2.Response
Upvotes: 4
Reputation: 59
I have encountered the same error after renaming the package in my project. everything worked fine except signed APK's with enabled minify. I have fixed it by adding this to my proguard-rules.pro:
-keep class retrofit2.** { *; }
-keepattributes *Annotation*
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-keep class com.yourproject.app.** { *; }
I suppose that the problem was in the last line. minifier might have been removing my classes because of package name mismatch, which is now prevented.
Upvotes: -1
Reputation: 1282
You need not downgrade your Gradle version solely for this purpose. When you update to Gradle 8 (or a version higher than 8), R8 will automatically be enabled in full mode. If you wish to revert to compact mode, simply add the following line to your gradle.properties file:
android.enableR8.fullMode=false
Happy coding!
Upvotes: 9
Reputation: 1764
This question is quite old but the problem seems to reappear from time to time. I had this error as well using Gradle 8.2.1
and com.android.tools.build:gradle 8.0.2
and a downgrade to com.android.tools.build:gradle 7.4.2
fixed it! But a downgrade is not really a solution, so I investigated a bit further
I was able to fix it by adding some of the Proguard rules from here (nameley Retrofit and Okhttp rules)
-keep class retrofit2.** { *; }
-keepattributes *Annotation*
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
You should also make sure that your retrofit and Okhttp versions are up-to-date and that you follow the proguard / R8 config hints laid out in the Readme
Upvotes: 29
Reputation: 8598
I had the same error on Release mode, no errors on Debug mode. Downgrade Gradle from 8.0.0 to 7.4.0 solved my problem.
Upvotes: 4
Reputation: 441
Dependencies
implementation "com.squareup.okhttp3:okhttp:4.9.0"
implementation 'com.squareup.okhttp3:logging-interceptor:4.7.2'
Calling Retrofit API
Get response in ResponseBody and then parse it to List of Object.
RetrofitAPI cashMemoService = RetrofitAPICLient.getClient().create(RetrofitAPI.class);
Call<ResponseBody> call = cashMemoService.getCashMemoPendingListObj(jsonBody);
Interface
@POST("GetCashMemoPunchingList")
Call<ResponseBody> getCashMemoPendingListObj(@Body RequestBody userData);
Upvotes: 3