Android IllegalArgumentException:无法为 retrofit2 创建调用适配器。电话<wh3>

Android IllegalArgumentException: Unable to create call adapter for retrofit2.Call<wh3>

提问人:Hector 提问时间:6/13/2023 最后编辑:Hector 更新时间:6/13/2023 访问量:133

问:

我遇到了以下运行时异常,我的 android 应用程序已从 AGP 升级到7.4.28.2.0-alpha07

java.lang.IllegalArgumentException: Unable to create call adapter for retrofit2.Call<wh3>
     for method MyApplicationServiceApi.siteUserLogin
    at retrofit2.Utils.methodError(SourceFile:5)
    at retrofit2.HttpServiceMethod.createCallAdapter(Unknown Source:12)
    at retrofit2.HttpServiceMethod.parseAnnotations(Unknown Source:67)
    at retrofit2.ServiceMethod.parseAnnotations(Unknown Source:18)
    at retrofit2.Retrofit.loadServiceMethod(Unknown Source:24)
    at retrofit2.Retrofit$1.invoke(Unknown Source:37)
    at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
    at $Proxy2.siteUserLogin(Unknown Source)
    at m03.siteUserLogin(Unknown Source:2)
    at k03$k.invokeSuspend(Unknown Source:47)
    at kl.resumeWith(Unknown Source:11)
    at mk0.run(Unknown Source:123)
    at f42$a.run(Unknown Source:3)
    at fb4.run(Unknown Source:2)
    at oa0.J(Unknown Source:0)
    at oa0$c.d(Unknown Source:14)
    at oa0$c.p(Unknown Source:28)
    at oa0$c.run(Unknown Source:0)
    Suppressed: mj0: [androidx.compose.ui.platform.s@839caba, ro@23c2d6b, z24{Cancelling}@53820c8, n@5931561]
 Caused by: java.lang.IllegalArgumentException: Return type must be parameterized as Call<wh3><ErrorBody, ResponseBody> or Call<wh3><out ErrorBody, out ResponseBody>
    at ep0.a(Unknown Source:194)
    at ep0.get(Unknown Source:33)
    at retrofit2.Retrofit.nextCallAdapter(Unknown Source:35)
    at retrofit2.Retrofit.callAdapter(Unknown Source:1)
    at retrofit2.HttpServiceMethod.createCallAdapter(Unknown Source:0)
    ... 16 more

我正在测试我的签名发布版本

buildTypes {
        getByName("release") {
            isMinifyEnabled = true
            isShrinkResources = true
            proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
        }
    }

我不明白为什么现在将 AGP 版本增加到 8+ 会导致我的发布版本崩溃。

AGP 8+ 需要哪些额外的 pro Guard 配置才能使我的发布版本正常运行?

我同时进行的其他重构是

increase android version from 33 to 34
refactored my gradle groovy build files to kts
increase kotlin version from 1.8.10 to 1.8.21
安卓 android-gradle-plugin proguard

评论

1赞 LethalMaus 6/13/2023
请尝试先使用 AGP 8.0.2,因为这是最后一个稳定版本。另外,请检查您使用 Call 的位置并确保参数匹配,因为返回类型必须参数化为 Call<wh3><ErrorBody、Response>Body 或 Call<wh3><out ErrorBody、out ResponseBody>

答:

0赞 Hector 6/13/2023 #1

我通过添加

-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
-keep,allowobfuscation,allowshrinking class arrow.retrofit.**

查看我的专业卫士规则