Search code examples
androidkotlinreleasefield-names

Kotlin automatically changes parameter names in release build


Json object's field name automatically changing in release build and causing api to fail.

Data Object :

data class SleepStage(val awake:Double, val light: Double, val rem:Double, val deep:Double)

IN DEBUG MODE

SleepStage": {"awake": 0.58,"light": 4.23,"rem": 1.28,"deep": 0.35 }

IN RELEASE MODE:

SleepStage": {"a": 0.58,"b": 4.23,"c": 1.28,"d": 0.35 }

Solution

  • This is called obfuscation. When you create a release version, Proguard shortens all variable names.

    Check out this StackOverflow post: Proguard - do not obfuscate Kotlin data classes

    It should be enough to add a @Keep annotation to your class:

    @Keep
    data class SleepStage(
        ...
    )