以下是我使用过的依赖项
implementation 'com.squareup.retrofit2:retrofit:2.0.2'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
下面是我调用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);
这是 RetrofitAPICLient
public static Retrofit getClient(){
if(retrofit == null){
retrofit = new Retrofit.Builder()
.baseUrl(newBseURL)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
下面是界面
@POST("GetCashMemoPunchingList")
Call<List<CashMemoDetails>> getCashMemoPendingListObj(@Body RequestBody userData);
以下是我得到的异常
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
请帮助我。提前致谢
这个问题很老了,但问题似乎时不时就会出现。我也使用过这个错误Gradle 8.2.1
and com.android.tools.build:gradle 8.0.2
并降级至com.android.tools.build:gradle 7.4.2
修复!但降级并不是真正的解决方案,所以我进一步研究了一些
我可以通过添加一些 Proguard 规则来修复它here https://github.com/krschultz/android-proguard-snippets/tree/master/libraries(nameley Retrofit 和 Okhttp 规则)
-keep class retrofit2.** { *; }
-keepattributes *Annotation*
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
您还应该确保您的 Retrofit 和 Okhttp 版本是最新的,并且遵循中列出的 proguard / R8 配置提示自述文件 https://github.com/square/retrofit#r8--proguard
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)