Search code examples
androidandroid-studiogson

Bug using Gson, Serialization and minified


At the beginning the app works fine(Emulator and physical device), but when I create the project and upload the application to the play store, just stop working(Login App).

I found when: minifyEnabled = true and upload the application the app always crash.

The app Crash with NullPointerException when GSON tries to deserialize.


Solution

  • for this case you need to add this in your file proguard-rules.pro this line.

    -keep class your.package.app.** { <fields>; }

    and in every file data class adding annotation

    @Keep

    This problem occurs when minify applies use R8 for obfuscation change names and this causes parsing fails