12

My Project has few classes that extends Parcelable. Do I need to 'keep' them in proguard rules while obfuscating.

What is the general practice for parcelables?

vijay_t
  • 776
  • 6
  • 14

2 Answers2

19

No, the default android rules include this:

-keepclassmembers class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator CREATOR;
}

These default rules will be applied if you leave the default generated gradle definition in place:

proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Make sure you do not forget the 'final' in your field definition! That was in my case the reason, why proguard removed it still.. – allofmex Dec 11 '19 at 19:22
7

If you are using Kotlin @Parcelize with proguard you can add this to proguard-rules.pro:

-keep @kotlinx.android.parcel.Parcelize public class *
Vahid Rajabi
  • 191
  • 3
  • 3
  • 3
    `kotlinx.android.parcel.Parcelize` is deprecated in favor of `kotlinx.parcelize.Parcelize` so this may need changing to `-keep @kotlinx.parcelize.Parcelize public class *` – Scott Cooper Oct 07 '22 at 10:54