Reputation: 704
My problem is happening only on published apk. The app installed through Android Studio works without any error. But the installed through Google Play is generating my JSON file using GSON library incorrectly, seem that it is not using my JSONEntity on published apk.
Correct: Generated file on my app using Android Studio:
{
"categories": [
{
"_id": 1,
"name": "General"
},
....
Wrong: Generated through download app from Google Play:
{
"a": [
{
"a": 1,
"b": "General"
}
],
...
Any idea why this occurs only on published app at Google Play?
Upvotes: 2
Views: 1045
Reputation: 704
This problem is caused due of ProGuard. ProGuard changes the Android code (because of security) but to avoid parse errors there is a need to add "exceptions" on used JSON files.
The default Proguard recommended configuration:
##---------------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 ----------
And specific for field names of used classes I had, also added:
-keepclassmembers class com.xxxxx.xxx.JSONEntity$XxxxEntity { <fields>; }
-keepclassmembers class com.xxxxx.xxx.JSONEntity { <fields>; }
And for each class that I want to generate the JSON file with the specific fields names of each attribute used the above code replacing the class names.
Upvotes: 6