Android: java.lang.ClassNotFoundException: Didn't find class "Fragment class here" on path: DexPathList

115 Views Asked by At

I'm working on a library module project that contains its own UX/UI with a single activity and a navigation graph using Navigation Component. I'm in the process of taking that module, publishing a release variant of it with minifyEnabled true and Proguard rules to a personal Github Packages repo, and implementing it in a fresh Android project. Aside from the standard Proguard rules and ConsumerProguardFiles specifically for library modules from what I read, I'm now at the stage where when I attempt to launch the module's activity in the fresh project, I get the following error at the top of the stack trace:

java.lang.RuntimeException: Unable to start activityComponentInfo{com.example.packagename/com.example2.packagename2.MainActivity}: android.view.InflateException: Binary XML file line #31 in com.example.packagename:layout/activity_main: Binary XML file line #31 in com.example.packagename:layout/activity_main: Error inflating class androidx.fragment.app.FragmentContainerView

MainActivity xml hosts the navigation graph

I get the following error at the end of the stack trace:

Caused by: java.lang.ClassNotFoundException: MyFragmentClass
   at java.lang.Class.classForName(Native Method)
   at java.lang.Class.forName(Class.java:454)
   at androidx.fragment.app.FragmentFactory.loadClass(FragmentFactory.java:53)
   at androidx.fragment.app.FragmentFactory.loadFragmentClass(FragmentFactory.java:94)
   ... 50 more
 Caused by: java.lang.ClassNotFoundException: Didn't find class "MyFragmentClass" on path: DexPathList...
   at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
   ... 54 more

MyFragmentClass is the entry fragment for the navigation graph.

I thought this was Proguard at work here, but I wrote -keep rules in the ConsumerProguardFiles file to explicitly keep the fragment class.

-keep class packagename.MyFragmentClass

And did so for all Fragment classes with destinations in the graph to be safe. No changes in error logs there.

I read that this may have to do with multiDex not being used, so I followed steps from https://developer.android.com/build/multidex#keep; extending my custom application to MultiDexApplication() and moved the keep rules from the consumerProguardFiles file for the fragment destinations into this multidex-config.pro file from the documentation, but I'm still hitting the same issue with ClassNotFoundException.

I've been at this for a long while now, and I'm unsure how else to proceed. This doesn't happen when I run a non-minified aar published to github packages, so something is definitely being obfuscated.

The DexPathList from the error log above, currently after enabling MultiDex and rule changes associated with it, is here:

DexPathList: [[dex file "/data/data/com.example.packagename/code_cache/.overlay/base.apk/classes3.dex", zip file "/data/app/~~6kA_gImFoxVpIpGEWOAh9g==/com.example.packagename-gdFV1iEfqaX11tSq9odycQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~6kA_gImFoxVpIpGEWOAh9g==/com.example.packagename-gdFV1iEfqaX11tSq9odycQ==/lib/arm64, /data/app/~~6kA_gImFoxVpIpGEWOAh9g==/com.example.packagename-gdFV1iEfqaX11tSq9odycQ==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]

Any help for this would be greatly appreciated. Thank you!

0

There are 0 best solutions below