android - Gradle 3.4.1 无法使用 Proguard 将响应解析为 Object

标签 android gradle retrofit proguard android-gradle-3.4.0

我刚刚将我的 Gradle 更新到 3.4.1。
我的一个模块中有一个 API 调用。
我在应用程序中使用模块:

implementation com.mindvalley.module_login:Module_Login:$rootConfiguration.loginLibraryVersion

现在,当我使用 生成签名版本时ProGuard ,对象为空,意味着改造无法解析对象。

附言:这适用于 Debug模式,或者如果我使用 Gradle 版本 3.3.2 运行应用程序

我的改造 Proguard 文件:
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions

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


-keepattributes Signature, InnerClasses, EnclosingMethod

-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations
-keepclassmembers,allowshrinking,allowobfuscation interface * {
    @retrofit2.http.* <methods>;
}

-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement

-dontwarn javax.annotation.**

-dontwarn kotlin.Unit

-dontwarn retrofit2.KotlinExtensions

-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface <1>


-dontwarn org.codehaus.mojo.**
-keepattributes *Annotation*

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

-keepattributes EnclosingMethod

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

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

我的 OkHttp proguard 文件:
-keepattributes Signature
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**

-dontwarn javax.annotation.**
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase

-dontwarn org.codehaus.mojo.animal_sniffer.*

-dontwarn okhttp3.internal.platform.ConscryptPlatform

-dontwarn org.codehaus.mojo.animal_sniffer.*

我的 GSON proguard 文件:
-keepattributes Signature
-keepattributes EnclosingMethod

-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }
-dontwarn com.google.gson.internal.UnsafeAllocator

-keepattributes Signature

-keepattributes *Annotation*

-dontwarn sun.misc.**
-keep class com.google.gson.examples.android.model.** { <fields>; }

-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.SerializedName <fields>;
}

最佳答案

P.S. : This works fine with debug mode or if I run the app with Gradle version 3.3.2



由于 Gradle 插件版本 3.4.0,D8/R8 默认启用,混淆将由 R8 而不是 ProGuard 完成。

Stick to ProGuard Obfuscation了解如何坚持使用 Proguard。

Android/java: Transition / Migration from ProGuard to R8? 了解如何迁移到 R8。

关于android - Gradle 3.4.1 无法使用 Proguard 将响应解析为 Object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56334209/

相关文章:

android - 定期任务的 ScheduledThreadPoolExecutor(使用 Retrofit)只触发一次,永远不会再触发

android - 无法解析符号 PreferenceFragmentCompat

android - 在 RetroFit 中处理来自同一端点的不同 JSON 响应类型

android - Robospice/Retrofit后台服务访问数据库

java - 如何知道哪个插件正在Gradle中添加 “run”任务

android - 顶级 build.gradle 文件中的 ext 属性

java - 在改造 1.9.0 中调用 api 时出错

android 如何在 Intents 之间切换

android - 如何将微调器中的特定项目设置为禁用状态

android-studio - Flutter build.gradle麻烦