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

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

Related

android- navigation component Parcelable arguments not found on release variant

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;
}

Fatal Exception at AnroidRuntime after releasing new update

After updating for a new release of my app I'm getting this error crash repeatedly on the opening of the app and nothing else. This crash happening after few seconds of the opening of the app.
Error Log:
E/AndroidRuntime: FATAL EXCEPTION: Thread-3
Process: com.company.app, PID: 13304
java.lang.NoSuchMethodError: No direct method <init>(Lorg/apache/http/c/c;Lorg/apache/http/conn/scheme/SchemeRegistry;)V in class Lorg/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager; or its super classes (declaration of 'org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager' appears in /system/framework/org.apache.http.legacy.boot.jar)
at com.a.g.c.c(Unknown Source:54)
at com.a.g.c.a(Unknown Source:4)
at com.a.e.b.a(Unknown Source:0)
at com.a.e.b.b(Unknown Source:23000)
at com.a.d.b.c(Unknown Source:5000)
at com.a.d.b.b(Unknown Source:0)
at com.a.d.b.a(Unknown Source:4000)
at com.a.c.f.a(Unknown Source:12000)
at com.a.c.f$1.run(Unknown Source:4)
at com.a.a.b.b.a(Unknown Source:8)
at com.a.e.a(Unknown Source:51031)
at com.a.e.a(Unknown Source:0)
at com.a.e$4.run(Unknown Source:1000)
at com.a.e.o(Unknown Source:31)
at com.a.e.a(Unknown Source:45000)
at com.a.c.a(Unknown Source:20)
at com.a.c.b(Unknown Source:27000)
at com.a.c$1.run(Unknown Source:7)
at com.a.a.b.c.run(Unknown Source:8)
at com.a.a.b.d.run(Unknown Source:2000)
This error is showing in Logcat not getting on Crashlytics.
What are the main causes of this happening and how to solve this problem?
What are the main causes of this happening and how to solve this problem?
This is due to your apache classes are stripped by your proguard obfuscation step. Try to add -keep options for those apache classes. E.g.
-keep class org.apache.http.** { *; }

java.lang.NoClassDefFoundError firebase Firestore android

Could not find
class 'com.google.firebase.firestore.QueryListenOptions', referenced from method com.firebase.ui.firestore.FirestoreRecyclerOptions$Builder.setQuery
07-20 18:23:10.220 10100-10100/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.dpvtechnology.zemon, PID: 10100
java.lang.NoClassDefFoundError: com.google.firebase.firestore.QueryListenOptions
at com.firebase.ui.firestore.FirestoreRecyclerOptions$Builder.setQuery(FirestoreRecyclerOptions.java:117)
Did you use progaurd?
If so, these type of problems usually are caused by it. Check your progaurd roles.
you can add this rule to your proguard rules to solve the problem
-keep class com.google.firebase.firestore.QueryListenOptions { *; }

Unable to instantiate activity ComponentInfo in android

I make a project and test it.
I test in my device Galaxy S7(Mashmellow), it works fine, but another device SHV-205(Kitkat), it occurs error like this.
09-23 15:24:45.981 10438-10438/com.thewell.thewell_dev.companylink E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.thewell.thewell_dev.companylink, PID: 10438
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.thewell.thewell_dev.companylink/com.thewell.thewell_dev.fourslink.Activity.SplashActivity}: java.lang.ClassNotFoundException: Didn't find class "com.thewell.thewell_dev.fourslink.Activity.SplashActivity" on path: DexPathList[[zip file "/data/app/com.thewell.thewell_dev.companylink-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.thewell.thewell_dev.companylink-1, /vendor/lib, /system/lib]]
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2306)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
at android.app.ActivityThread.access$900(ActivityThread.java:175)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
I use android studio.
I test it and upload to Google play store, but it works fine.
I don't know why this problem occurs this error.
please help me
I faced this Error already, and found the solution myself,
If you are placed you splashscreen activity in your Activity package, please move it to outer package(Main package)
as shown in below Image..!

Android NoSuchMethodException: callDrawGLFunction

I find the method is reanme to callDrawGLFunction2 at the android version of 5.1.0 . And add the class of com.android.webview.chromium.WebViewDelegateFactory at the same time.
But i don't know how to fix the bug. can anyone have idea.
full stack:
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
... 25 more
Caused by: android.util.AndroidRuntimeException: java.lang.RuntimeException: Invalid reflection
at android.webkit.WebViewFactory.getProvider(WebViewFactory.java)
at android.webkit.WebView.getFactory(WebView.java)
at android.webkit.WebView.ensureProviderCreated(WebView.java)
at android.webkit.WebView.setOverScrollMode(WebView.java)
at android.view.View.init(View.java)
at android.view.View.init(View.java)
at android.view.ViewGroup.init(ViewGroup.java)
at android.widget.AbsoluteLayout.init(AbsoluteLayout.java)
at android.webkit.WebView.init(WebView.java)
at android.webkit.WebView.init(WebView.java)
at android.webkit.WebView.init(WebView.java)
at android.webkit.WebView.init(WebView.java)
... 27 more
Caused by: java.lang.RuntimeException: Invalid reflection
at com.android.webview.chromium.WebViewDelegateFactory$Api21CompatibilityDelegate.init(WebViewDelegateFactory.java:258)
at com.android.webview.chromium.WebViewChromiumFactoryProvider.init(WebViewChromiumFactoryProvider.java:2106)
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.Class.newInstance(Class.java:1690)
... 39 more
Caused by: java.lang.NoSuchMethodException: callDrawGLFunction [long]
at java.lang.Class.getMethod(Class.java:671)
at com.android.webview.chromium.WebViewDelegateFactory$Api21CompatibilityDelegate.init(WebViewDelegateFactory.java:246)
... 42 more
android.view.InflateException: Binary XML file line #21: Error inflating class android.webkit.WebView
at android.view.LayoutInflater.createView(LayoutInflater.java)
It's not application error.
The bug is all report from the device of sdk 22. But the method is already rename in that version.
I send email to google developer who rename the method from callDrawGLFunction to callDrawGLFunction2. I got some reply:
"Api21CompatibilityDelegate means webview believes it's running on 21. Renaming callDrawGLFunction happened after API21, hence webview is trying look for the old name."
So It's obvious device rom bug.

Categories

Resources