Home > Net >  Gson and Ktor production build converts json names to letters
Gson and Ktor production build converts json names to letters

Time:12-03

I use Gson to create a Json string when sending data from my Android app back to the server using Ktor.

Works fine for debug release, but under release Gson appears to convert all the member names to letters

How it should look: enter image description here

How it looks on release compile: enter image description here

This must be a configuration to set somewhere? How do I force Gson to retain variable names?

CodePudding user response:

Release build minification obfuscates names, including your model class fields. Some options:

  1. You can add gson's @SerializedName("field") annotations to your model class fields to specify the JSON names to be used with those fields despite obfuscation.

  2. You can add -keep rules to your R8/Proguard configuration file to prevent your model classes from being obfuscated.

  • Related