我有一个自定义列表,我使用Gson来转换为jsonArray。
问题是,如果我使用的是调试版本apk,它运行得很好,但是如果我使用的是版本apk,那么键就会发生变化。
示例:
Debug version -> "name", "Mary"
Release version -> "a", "Mary"所有键都改为"a,b,c.“
两种版本我都有护卫。
我的代码:
Gson gson = new Gson();
JsonArray jsonArray = gson.toJsonTree(myCustomList).getAsJsonArray();分级代码:
buildTypes {
release {
debuggable true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}前守卫代码:
-dontwarn okhttp3.**
-dontwarn okio.**
##---------------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
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }
# Prevent proguard from stripping interface information from TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer我用包名添加了-keep class yourPackageName.data.model.** { *; },但也遇到了同样的问题。
发布于 2017-07-15 22:09:32
我猜您的调试生成没有启用minify。因此,当发生混淆时,您需要保留模型类。此示例旨在将所有模型类保存在指定的包-keep class yourPackageName.data.model.** { *; }中。
发布于 2019-11-21 12:18:08
保持您的会员班:
class Name{
@SerializedName("fNmae")
private String fNmae;
}
-keepclassmembers class com.integration.Name{
private *;
}https://stackoverflow.com/questions/45122322
复制相似问题