Home > Back-end >  android- navigation component Parcelable arguments not found on release variant
android- navigation component Parcelable arguments not found on release variant

Time:10-05

i have a strange Error, I'm developing an app and I'm using navigation component, i need to pass Custom Parcelable objects to some fragments using safeArgs, actually the app works fine on debug builds, unfortunately when tried to launch the app on release mode the app throws a FATAL EXCEPTION. Models are in a separated module, do i need to add a specific config in this module?

this is an example of the models

@Parcelize
@Serializable
data class Article(
    val articleId: Int,
///
) : Parcelable

this is the stack Trace of exception:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: ..., PID: 11381
    java.lang.RuntimeException: Unable to start activity ComponentInfo{...MainActivity}: android.view.InflateException: Binary XML file line #101 in .....:layout/activity_main: Binary XML file line #101 in ...:layout/activity_main: Error inflating class androidx.fragment.app.FragmentContainerView
        at.... //
     Caused by: android.view.InflateException: Binary XML file line #101 in ....:layout/activity_main: Binary XML file line #101 in ....:layout/activity_main: Error inflating class androidx.fragment.app.FragmentContainerView
     Caused by: android.view.InflateException: Binary XML file line #101 in ....:layout/activity_main: Error inflating class androidx.fragment.app.FragmentContainerView
     Caused by: java.lang.RuntimeException: Exception inflating ....:navigation/navigation line 168
       //....
E/AndroidRuntime:     at ...///
     Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: ......app_models.Article
        at p4.o.a(NavType.java:181)
        at androidx.navigation.g.e(NavInflater.java:191)
        at androidx.navigation.g.g(NavInflater.java:155)
        at androidx.navigation.g.b(NavInflater.java:128)
        at androidx.navigation.g.b(NavInflater.java:141)
        at androidx.navigation.g.c(NavInflater.java:88)
            ... 42 more
     Caused by: java.lang.ClassNotFoundException: ....app_models.Article
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:454)
        at java.lang.Class.forName(Class.java:379)
        at p4.o.a(NavType.java:169)
            ... 47 more
     Caused by: java.lang.ClassNotFoundException: Didn't find class "....app_models.Article" on path: DexPathList[[zip file "/data/app/~~Frr3Sf0kFWBoEFseLYT-jQ==/....-BW1tOT8d2hUlYJyi1fggPw==/base.apk"],nativeLibraryDirectories=[/data/app/~~Frr3Sf0kFWBoEFseLYT-jQ==/...-BW1tOT8d2hUlYJyi1fggPw==/lib/x86, /system/lib, /system_ext/lib]]

Nb: i've replaced the package names with 3 dots thank you

CodePudding user response:

You need to add at least the following to your Proguard config:

-keepnames class * implements android.os.Parcelable

Although it can also make sense to make sure the CREATOR field is kept

-keepnames class * implements android.os.Parcelable

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

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}
  • Related