android- navigation component Parcelable arguments not found on release variant - android

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

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

Dynamic feature: Unable to instantiate fragment : make sure class name exists

I'm trying to load my fragment that lives in a dynamic feature module. However, I keep getting a crash:
val f = FragmentFactory().instantiate(classLoader,
"com.myapp.customviewdynamicfeature.CustomFragment")
supportFragmentManager.beginTransaction()
.add(R.id.customFragmentContainer, f).commit()
2022-03-25 11:36:54.020 20732-20732/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.myapp.dynamicdeliverysampleapp, PID: 20732
androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.myapp.customviewdynamicfeature.CustomFragment: make sure class name exists
at androidx.fragment.app.FragmentFactory.loadFragmentClass(FragmentFactory.java:97)
at
I also tried adding this to my dynamic module's proguard
-keep class com.myapp.customviewdynamicfeature.** { *; }
I've also tried reflection:
val f = Class.forName("com.myapp.customviewdynamicfeature.CustomFragment").newInstance() as Fragment
but I get a similar error:
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:558)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003) 
Caused by: java.lang.ClassNotFoundException: com.myapp.customviewdynamicfeature.CustomFragment
I believe I resolved this by upgrading the AndroidX fragment version to 1.5.0.
https://developer.android.com/jetpack/androidx/releases/fragment#version_15_2

Error inflating class androidx.appcompat.widget.AppCompatSpinner

We are seeing a crash Error inflating class androidx.appcompat.widget.AppCompatSpinner on the play console,but we are not able to reproduce it.
Here is my xml :
<androidx.appcompat.widget.AppCompatSpinner
android:id="#+id/spinnerState"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/xMargin_42_156"
android:layout_marginEnd="#dimen/xMargin_42_156"
android:background="#drawable/spinner_down_arrow"
android:focusableInTouchMode="true"
android:overlapAnchor="false"/>
In build.gradle
implementation 'androidx.appcompat:appcompat:1.2.0'
Logs:
Fatal Exception: java.lang.RuntimeException
Unable to start activity ComponentInfo{com.wrap/com.wrap.activities.NewIntroActivity}: android.view.InflateException: Binary XML file line #129 in com.wrap:layout/activity_new_intro: Binary XML file line #129 in com.wrap:layout/activity_new_intro: Error inflating class androidx.appcompat.widget.AppCompatSpinner

FragmentContainerView with SupportMapFragment crashes when minify is enabled

I have the following layout:
<androidx.fragment.app.FragmentContainerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/map"
tools:context=".map.MapActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />
It works fine with my debug build, but my release build with minify enabled crashes.
09-04 15:14:06.727 15555 15555 E AndroidRuntime: android.view.InflateException: Binary XML file line #8: Binary XML file line #8: Error inflating class androidx.fragment.app.FragmentContainerView
09-04 15:14:06.727 15555 15555 E AndroidRuntime: Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class androidx.fragment.app.FragmentContainerView
09-04 15:14:06.727 15555 15555 E AndroidRuntime: Caused by: androidx.fragment.app.Fragment$c: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists
Any suggestions on how to fix it? If I replace the FragmentContainerView with the old fragment view, it works.
The problem might be related to minification. If you have minify enabled, you probably have to add something similar to this to your proguard:
-keep class com.google.android.gms.maps.** { *; }
This is caused by a bug in aapt2, and is being tracked in a bug by google here: https://issuetracker.google.com/issues/142601969
In the meantime, the easiest way to fix this is to add #Keep to any fragments that you use in this manner.
If it's a fragment from a library where you are unable to modify the code, you can add it as a rule in your proguard.cfg:
-keep class om.google.android.gms.maps.** { *; }

com.android.support:design with androidX (1.0.2)

I want to use TextInputLayout inside my project, but I'm using androidX library
implementation "androidx.appcompat:appcompat:1.0.2"
/*this don't work*/
implementation "com.android.support:design:28.0.0"
This is the exception which I'm facing
android.view.InflateException: Binary XML file line #30: Binary XML file line #30: Error inflating class android.support.design.widget.TextInputLayout
Caused by: android.view.InflateException: Binary XML file line #30: Error inflating class android.support.design.widget.TextInputLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.design.widget.TextInputLayout" on path: DexPathList[[zip file "/data/app/com.example
Error inflating class android.support.design.widget.TextInputLayout
Caused by: java.lang.ClassNotFoundException: Didn't find class
This error thrown when the Java Virtual Machine (JVM) tries to load a particular class and the specified class cannot be found in the classpath.
You should use
com.google.android.material.textfield.TextInputLayout
DEMO
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</com.google.android.material.textfield.TextInputLayout>
Then Clean-Rebuild-Run.

Error Unable to instantiate service com.google.firebase.iid.FirebaseInstanceIdService: java.lang.ClassNotFoundException- in Proguard Enabled release

I am getting below mentioned error,
I cleaned the project, also Invalidate and restart done. but still same problem.
Proguard is enabled.-android studio:3.3.1
java.lang.RuntimeException: Unable to instantiate service com.google.firebase.iid.FirebaseInstanceIdService: java.lang.ClassNotFoundException: Didn't find class
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.firebase.iid.FirebaseInstanceIdService" on path: DexPathList
Simple add -keep class com.google.firebase.iid.FirebaseInstanceIdService in your ProGuard configuration file.

Categories

Resources