下面是我使用的一些技巧
implementation 'com.squareup.retrofit2:retrofit:2.0.2'
implementation 'com.squareup.retrofit2:converter-gson:2.0.2'
字符串
下面是我称之为改造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
型
请帮助我在这方面。提前感谢
6条答案
按热度按时间dba5bblo1#
这个问题已经很老了,但这个问题似乎时不时地会出现。我在使用
Gradle 8.2.1
和com.android.tools.build:gradle 8.0.2
时也遇到过这个错误,降级到com.android.tools.build:gradle 7.4.2
解决了这个问题!但是降级并不是一个真正的解决方案,所以我进一步调查了一下。我能够通过添加一些来自here的Proguard规则(nameley Retrofit和Okhttp规则)来修复它。
字符串
您还应该确保您的reflective和Okhttp版本是最新的,并且您遵循了自述文件中列出的proguard / R8配置提示
9bfwbjaz2#
您不需要仅为此目的降级您的Gradle版本。当您更新到Gradle 8(或高于8的版本)时,R8将自动启用完整模式。如果您希望恢复到精简模式,只需在您的gradle.properties文件中添加以下行:
设置为“否”
编码愉快!
toiithl63#
我在发布模式下也有同样的错误,在升级模式下没有错误。将Gradle从8. 0. 0降级到7. 4. 0解决了我的问题。
zvms9eto4#
不确定性
字符串
调用Retrofit API
在ResponseBody中获取response,然后将其解析为List of Object。
型
接口
型
pbwdgjma5#
我在项目中重命名包后遇到了同样的错误。除了启用缩小的签名APK外,一切正常。我已经通过将此添加到我的proguard-rules.pro修复了它:
字符串
我想问题是在最后一行。minifier可能已经删除了我的类,因为包名不匹配,现在被阻止了。
goucqfw66#
我也有这个错误.一切正常,除了签署APK的启用缩小.我已经通过添加一些规则到proguard-rules.pro文件修复它.一般来说,对于翻新,你需要添加以下规则到proguard-rules.pro:
字符串