【问题标题】:Retrofit 2.3.0 Error while generating signed APKRetrofit 2.3.0 生成签名 APK 时出错
【发布时间】:2017-10-15 09:38:07
【问题描述】:

我已经更新了 Retrofit v 2.3.0 和 okhttp 3.8.0 和 okio 1.13.0 但现在当我尝试生成签名的 APK 时出现以下错误:

Warning:retrofit2.OkHttpCall: can't find referenced class javax.annotation.concurrent.GuardedBy
Warning:there were 3 unresolved references to classes or interfaces.
Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.

Job failed, see logs for details 

以下是他们建议的我用于 Retrofit 和 OKHTTP 的 proguard 规则

# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions
-dontwarn org.xmlpull.v1.**
-dontwarn okhttp3.**
-keep class okhttp3.** { *; }
-dontwarn okio.**
-dontwarn javax.annotation.Nullable
-dontwarn javax.annotation.ParametersAreNonnullByDefault

我还需要补充什么? 任何帮助将不胜感激。

【问题讨论】:

  • 尝试添加这些:-dontwarn retrofit2.** -keep class retrofit2.** { ; } -keepattributes 签名 -keepattributes 例外 -keepclasseswithmembers 类 * { @retrofit2.http. ; }

标签: android proguard retrofit2


【解决方案1】:

正如 JakeWharton 在 GitHub 上所说,我们只需要添加以下行:

-dontwarn javax.annotation.**

不需要这个

-keep class okhttp3.** { *; }

【讨论】:

    【解决方案2】:

    确保在 Proguard 中包含以下行以使用 Retrofit 2

    -dontwarn retrofit2.**
    -keep class retrofit2.** { *; }
    -keepattributes Signature
    -keepattributes Exceptions
    
    -keepclasseswithmembers class * {
        @retrofit2.http.* <methods>;
    }
    -keepclasseswithmembers interface * {
        @retrofit2.http.* <methods>;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-08
      • 1970-01-01
      • 1970-01-01
      • 2018-06-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多