我刚刚将我的 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/