GSON:仅在发布的应用程序中使用my JSONEntity无法正确创建,使用Android Studio可以正常工作

GSON:仅在发布的应用程序中使用my JSONEntity无法正确创建,使用Android Studio可以正常工作,android,gson,Android,Gson,我的问题只发生在已发布的apk上。通过Android Studio安装的应用程序运行正常,没有任何错误。但是通过GooglePlay安装的程序错误地使用GSON库生成了我的JSON文件,似乎它没有在已发布的apk上使用我的JSONEntity 更正:使用Android Studio在我的应用程序上生成的文件: 错误:通过从Google Play下载应用程序生成: 你知道为什么只有在Google Play上发布的应用程序才会出现这种情况吗?这个问题是由ProGuard引起的。 ProGuard出于

我的问题只发生在已发布的apk上。通过Android Studio安装的应用程序运行正常,没有任何错误。但是通过GooglePlay安装的程序错误地使用GSON库生成了我的JSON文件,似乎它没有在已发布的apk上使用我的JSONEntity

更正:使用Android Studio在我的应用程序上生成的文件:

错误:通过从Google Play下载应用程序生成:


你知道为什么只有在Google Play上发布的应用程序才会出现这种情况吗?

这个问题是由ProGuard引起的。 ProGuard出于安全考虑更改了Android代码,但为了避免解析错误,需要在使用过的JSON文件上添加异常

Proguard推荐的默认配置:

##---------------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.** { *; }

##---------------End: proguard configuration for Gson  ----------
对于我使用过的类的字段名,还添加了:

-keepclassmembers class com.xxxxx.xxx.JSONEntity$XxxxEntity { <fields>; }
-keepclassmembers class com.xxxxx.xxx.JSONEntity { <fields>; }

对于我想要生成JSON文件的每个类,每个属性的特定字段名都使用上述代码替换类名。

我确信这与Google Play或Android Studio无关。显然,json文本在这两种情况下的解析方式不同。它是同一个类,通过相同的过程生成。我不知道为什么会产生不同的结果。同样的方法,在Android Studio的应用程序上,在Google Play上签署了apk。
##---------------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.** { *; }

##---------------End: proguard configuration for Gson  ----------
-keepclassmembers class com.xxxxx.xxx.JSONEntity$XxxxEntity { <fields>; }
-keepclassmembers class com.xxxxx.xxx.JSONEntity { <fields>; }