androidproguardnavigation-architecture

ClassNotFoundException when using SafeArgs with Proguard and Navigation Architecture Component?


I'm using SafeArgs plugin and Navigation Architecture Component but the app is crashing.

Caused by: java.lang.ClassNotFoundException: Didn't find class "com.package.domain.models.Model"

I'm using minifyEnabled true in the Gradle.

Also, I have three modules app, data, and domain. So, in all three proguard-rules files I have added

-keepnames class com.package.domain.models.Model1
-keepnames class com.package.domain.types.ImageType
-keepnames class com.package.domain.models.Model

I'm using these three classes as argType in my Navigation graph.

But the app is still crashing. Any help would be appreciated.


Solution

  • I think the more appropriate thing to do would be adding this to add these in my proguard-rules file(s).

    -keepnames class * extends android.os.Parcelable
    -keepnames class * extends java.io.Serializable
    

    As I don't have to keep annotating my models with @Keep which are Parcelable or Serializable or keeping the whole model package away from obfuscation.

    Check this for more information.