Proguard causing runtime exception with Android Navigation Component

I know that Proguard and R8 should be keeping all the children of library classes but in this case, the fragment class seems to be missing. This keep rule solved my issue but technically we should not need this rule at all!

-keep class * extends android.support.v4.app.Fragment{}

If you are using AndroidX, then use this rule: -keep class * extends androidx.fragment.app.Fragment{}

If you use argType in your navigation XML, you also need a rule for the referenced classes, for example: -keep class com.example.model.MyModel. Or even better, exclude parcelable and serializable classes from being renamed, as recommended by the official documentation.

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

Leave a Comment