Search code examples
androidkotlindagger-hilt

Unable to instantiate appComponentFactory: java.lang.ClassNotFoundException


Actually, I was working on one project and to test the implemented feature, I have build the project but unfortunately, i have got the error like: "Unable to instantiate appComponentFactory" .

I didn't change any kind of gradle or manifest related changes. Just restructure gson response model based restructured API and based on that model, I have also modified some model mapping. and for API calling, I am using retrofit.

I have just added Hilt dependency into app level gradle and did some required changes into the project level gradle as per google documentation.

Here, I want to understand the root of this error.

Thank you in advance!

Here is the error response which i am facing!

Unable to instantiate appComponentFactory
java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList[[],nativeLibraryDirectories=[/data/app/com.<ProjectName>.app-uNyluFOJTyG6uVYYO-7V6w==/lib/arm64, /data/app/com.<ProjectName>.app-uNyluFOJTyG6uVYYO-7V6w==/base.apk!/lib/arm64-v8a, /system/lib64]]
                                                                                                        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
                                                                                                        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
                                                                                                        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                                                        at android.app.LoadedApk.createAppFactory(LoadedApk.java:226)
                                                                                                        at android.app.LoadedApk.updateApplicationInfo(LoadedApk.java:338)
                                                                                                        at android.app.ActivityThread.handleDispatchPackageBroadcast(ActivityThread.java:5388)
                                                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1733)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:106)
                                                                                                        at android.os.Looper.loop(Looper.java:193)
                                                                                                        at com.android.server.SystemServer.run(SystemServer.java:454)
                                                                                                        at com.android.server.SystemServer.main(SystemServer.java:294)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:838)

I have tried many things which are mentioned into one stackOverflow Question.

Didn't find class "androidx.core.app.CoreComponentFactory"

Also, refer some other asked Questions related to the same from the StackOverflow as well as from other sources, but not getting any solution!

But, not a single answer worked for me.


Solution

  • In my past, I had faced same issue and resolved by changing the following things into gradle.

    implementation 'com.android.support:multidex:x.x.x'
    

    to

    implementation 'androidx.multidex:multidex:x.x.x'
    

    and have enabled multidex enabled into build.gradle file in defaultConfig section like:

    multiDexEnabled true