【问题标题】:Retrofit warning with Proguard使用 Proguard 进行改造警告
【发布时间】:2017-10-27 01:51:53
【问题描述】:

我在我的 android 项目中打开了 proguard 并收到以下警告。在谷歌上搜索,但找不到太多信息。

警告:retrofit.Platform$Java8:找不到引用的类 org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

我已经在我的项目中加入了 retrofit2 proguard 规则。

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

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

【问题讨论】:

    标签: android proguard android-proguard


    【解决方案1】:

    对 Retrofit 2.3.0 和 okhttp 3.8.0 使用以下 proguard 规则

    -dontnote retrofit2.Platform
    -dontwarn retrofit2.Platform$Java8adapters.
    -keepattributes Signature
    -keepattributes Exceptions
    -dontwarn org.xmlpull.v1.**
    -dontwarn okhttp3.**
    -dontwarn okio.**
    -dontwarn javax.annotation.**
    

    【讨论】:

    • 改造主页上的官方规则,加上-dontwarn javax.annotation.**是我的必填项
    【解决方案2】:

    改成这样:

    -dontwarn okio.**
    -dontwarn retrofit2.Platform$Java8
    

    在 Java 8 VM 上运行时,Retrofit 页面已注意到此 proguard 版本:

    为什么会这样?

    原因是: 编译器尝试引用 Java 8 类,当你通过 Proguard 不提及时,明确提及后,Java 8 类将不会被使用。 例如 Java 8 的 java.nio.* 包在 Android 上不可用,并且永远不会被调用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多