Home > Blockchain >  Kotlin automatically changes parameter names in release build
Kotlin automatically changes parameter names in release build

Time:02-02

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 }

CodePudding user response:

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(
    ...
)
  • Related