android- 在发布变体上找不到导航组件 Parcelable 参数
android- navigation component Parcelable arguments not found on release variant
我有一个奇怪的错误,我正在开发一个应用程序并且我正在使用 navigation component
,我需要使用 safeArgs
将自定义 Parcelable
对象传递给一些片段,实际上该应用程序在调试版本上运行良好,不幸的是,当尝试在发布模式下启动该应用程序时,该应用程序抛出
FATAL EXCEPTION
。
模型在一个单独的模块中,我需要在这个模块中添加特定的配置吗?
这是模型示例
@Parcelize
@Serializable
data class Article(
val articleId: Int,
///
) : Parcelable
这是异常的堆栈跟踪:
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: 我已经用 3 个点替换了包名
谢谢
您至少需要将以下内容添加到您的 Proguard 配置中:
-keepnames class * implements android.os.Parcelable
尽管确保保留 CREATOR 字段也很有意义
-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;
}
我有一个奇怪的错误,我正在开发一个应用程序并且我正在使用 navigation component
,我需要使用 safeArgs
将自定义 Parcelable
对象传递给一些片段,实际上该应用程序在调试版本上运行良好,不幸的是,当尝试在发布模式下启动该应用程序时,该应用程序抛出
FATAL EXCEPTION
。
模型在一个单独的模块中,我需要在这个模块中添加特定的配置吗?
这是模型示例
@Parcelize
@Serializable
data class Article(
val articleId: Int,
///
) : Parcelable
这是异常的堆栈跟踪:
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: 我已经用 3 个点替换了包名 谢谢
您至少需要将以下内容添加到您的 Proguard 配置中:
-keepnames class * implements android.os.Parcelable
尽管确保保留 CREATOR 字段也很有意义
-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;
}