3

I have this class:

@Parcelize
data class UserData(val name: String = "", val country: String = ""):Parcelable

In the proguard rules i have:

-keep class com.example.app.model.UserData

Then i use this in the repo (from Firebase):

val userdata = firestoreDoc.toObject(UserData::class.java)

If i disable minifyEnabled it works fine and userData gets populated, but when i enable it, it returns an empty UserData object.

I noticed that if i add the @Keep annotation to the UserData class it works as expected but i don't understand why.

Doesn't the proguard rules already keep the class? Do i need to add a rule for kotlin parcelize?

android_dev
  • 3,886
  • 1
  • 33
  • 52
Puntogris
  • 325
  • 2
  • 13
  • 1
    I'm not quite sure, but I faced a similar issue. I think the reason is, that Kotlin classes are converted into java classes, named "UserDataKt" for UserData.kt. I think proguard is not capable of distinguishing between Java and Kotlin, and therefore the keep instruction doesn't work. – the_dani Jul 27 '21 at 19:42
  • The reason could be that Parcelize plugin generates additional classes, you can check decompiled code of your Kotlin class in Android Studio. If you want to have rules without the Keep annotation see the answers here https://stackoverflow.com/a/36076888/1635488 – android_dev Jul 27 '21 at 19:45
  • I believe you need to specify to keep the class members as well, i.e. `-keep class com.example.app.model.UserData { *; }` Still, I would recommend just using the `@Keep` annotation, personally. – Kevin Coppock Jul 28 '21 at 14:22

0 Answers0