##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature
# For using GSON @Expose annotation
-keepattributes *Annotation*
# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.bean.** {*;}
# Prevent proguard from stripping interface information from TypeAdapter, TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer
# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
@com.google.gson.annotations.SerializedName <fields>;
}
##---------------End: proguard configuration for Gson ----------
注:将上面的 com.google.gson.examples.android.model 换成你自己项目的实体类的包名!!!
Gson 官方混淆地址:https://github.com/google/gson/blob/master/examples/android-proguard-example/proguard.cfg
本文详细介绍了如何配置ProGuard以确保Gson在混淆代码过程中正常工作,包括保留泛型类型信息、注解、特定类及成员,适用于Android应用中使用Gson进行序列化和反序列化的场景。
449

被折叠的 条评论
为什么被折叠?



