Obfuscation Parcelable and Serializable for Navigation Component
Last couple of years, as Android Developers we use Navigation Component for navigation structure of our applications or change existing navigation structure to it. Navigation Component provides us the speed to connect screen with each other and setup deep link structure easily.
I don’t tell you everything from the beginning. What is deep link?, What is nav-graph? bla bla . But I just want to pay attention to argType for navigations.
Sometimes we need to use string, integers, long primitive types to pass arguments between screen (Fragments, Activities etc). In some other cases, we need entities to pass into another screen. Before navigation component, we could make this with Bundle and Intents. Actually Navigation Component uses this structure in the background. Here is important, if you want to move entities as arguments to another screen you must inherit your entity classes from Parcelable or Serializable. At this point everything is OK. 👌
You complete your application and want to send to Google Play Store. You should shrink and obfuscate your codes with Proguard or Dexguard. When you use parcelable class as argType for navigation argument, just add below codes into your proguard files, otherwise your application will get a crash 😔.
-keepnames class * extends android.os.Parcelable
-keepnames class * extends java.io.Serializable
Happy coding my friends, I hope this info will help you all.