Ajay J G
Ajay J G

Reputation: 926

SerializedName annotated member is getting obfuscated in release build Android

In recent release build creation, one of my classes which had @SerializedName member was getting obfuscated, which didn't happen in previous release.

My class:

data class Segments(
        @SerializedName("list")
        val list: List<Segment>
)

Using -keepattributes *Annotation* also in proguard.

Please can anybody help me, what is wrong here?

Upvotes: 0

Views: 822

Answers (1)

Ajay J G
Ajay J G

Reputation: 926

I spent lot of time figuring out why my other class members are not obfuscated and not getting any null pointer crash.

Firstly Invalidate cache and restart mostly it will be caching issue.if not working try below solution.

(My assumption is Proguard/R8 is messing up this). I know I can use @Keep but I don't wanted to do that, as it was @SerializedName Annotation. Later found the fix,

  1. Initialised data member

  2. Annotated with @Parcelize and implemented Parcelable,

     @Parcelize
     data class Segments(
         @SerializedName("list")
         val segments: List<HomeFSegmentsSegment> = ArrayList()
     ) : Parcelable
    

This may/may not be exact solution to the problem, but it did solve the issue.

Upvotes: 0

Related Questions