我有一个自定义列表,我正在使用Gson将其转换为jsonArray。
问题是,如果我使用调试版本apk,它可以完美地工作,但是如果我使用发布版本apk,则键会改变。
例如:
Debug version -> "name", "Mary"
Release version -> "a", "Mary"
所有的键都更改为"a, b, c..."
我在两个版本中都使用了Proguard。
我的代码:
Gson gson = new Gson();
JsonArray jsonArray = gson.toJsonTree(myCustomList).getAsJsonArray();
Gradle代码:
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'
}
}
ProGuard代码:
-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.** { *; }
与我的包名,但我仍然遇到了同样的问题。