【问题标题】:Retrofit2 - Missing either @GET URL or @Url parameter - ProguardRetrofit2 - 缺少 @GET URL 或 @Url 参数 - Proguard
【发布时间】:2018-06-19 20:29:36
【问题描述】:

我在我的应用程序中做 ProGuard:

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

当我尝试使用 Retrofit2 进行 http 调用时,我得到了异常:

java.lang.IllegalArgumentException:缺少@GET URL 或@Url 参数。

Service 是:

interface ContentService {

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

}

minifyEnabled falseshrinkResources false 时不会发生这种情况

我在互联网上进行了研究,最终将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 是否存在问题。

【问题讨论】:

  • 您是否尝试添加具有这些方法调用 post 或 get 的接口。我认为您也可以尝试在规则中添加它们。因为它可能也会缩小它们。
  • 这是真的@vikaskumar,它就是这样工作的。就没有别的办法了吗?
  • 试试这个#-keep class com.your.package.webinterface.;

标签: android retrofit2 proguard minify


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2017-02-25
    • 2023-03-03
    • 2019-10-31
    • 2016-12-06
    • 1970-01-01
    • 2011-12-29
    • 2016-06-10
    • 2010-10-16
    相关资源
    最近更新 更多