gpt4 book ai didi

android - Retrofit2 - 缺少@GET URL 或@Url 参数 - Proguard

转载 作者:太空狗 更新时间:2023-10-29 13:05:51 28 4
gpt4 key购买 nike

我在我的应用中使用 ProGuard 作为:

        shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

当我尝试使用 Retrofit2 进行 http 调用时,出现异常:

java.lang.IllegalArgumentException: Missing either @GET URL or @Url parameter.

服务是:

interface ContentService {

@GET
fun getCMSCon(@Url url: String): Single<CMSCon>

}

minifyEnabled falseshr​​inkResources false 时不会发生这种情况

我在 Internet 上进行了研究,最终将 proguard-rules.pro 修改为:

# Retrofit
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-keepattributes *Annotation*

-keepattributes RuntimeVisibleAnnotations
-keepattributes RuntimeInvisibleAnnotations
-keepattributes RuntimeVisibleParameterAnnotations
-keepattributes RuntimeInvisibleParameterAnnotations

-keepattributes EnclosingMethod

-keepclasseswithmembers class * {
@retrofit2.* <methods>;
}

-keepclasseswithmembers interface * {
@retrofit2.* <methods>;
}

但没有任何改变。

@Url 是从 res 和文字传递过来的,以检查 Flavors 是否存在问题。

最佳答案

解决方案是在任何 interface 作为服务描述的任何调用中应用 @Keep:

@Keep
@GET
fun getCMSConfig(@Url url: String): Single<CMSConfig>

关于android - Retrofit2 - 缺少@GET URL 或@Url 参数 - Proguard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48191327/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com