87

I don't know what to do about the following errors, I've searched the web but not found anything:

java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList[[],nativeLibraryDirectories=[/data/app/com.example.padmw-CXElJ_vfrfm3y7py3CPsJw==/lib/x86, /system/lib]]
    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)

and :

2019-08-29 00:19:24.071 1853-1853/? E/LoadedApk: Unable to instantiate appComponentFactory
java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList[[],nativeLibraryDirectories=[/data/app/com.example.padmw-CXElJ_vfrfm3y7py3CPsJw==/lib/x86, /system/lib]]
    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)

my dependencies in gradle app :

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.firebase:firebase-core:17.1.0'
implementation 'com.google.firebase:firebase-database:19.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.navigation:navigation-fragment:2.0.0'
implementation 'androidx.navigation:navigation-ui:2.0.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.firebaseui:firebase-ui-database:1.2.0'
}
apply plugin: 'com.google.gms.google-services'
Kasım Özdemir
  • 5,414
  • 3
  • 18
  • 35
Chris911
  • 909
  • 1
  • 6
  • 10
  • 2
    Possible duplicate of [After migration to AndroidX, exception at start up: java.lang.ClassNotFoundException: "Didn't find class androidx.core.app.CoreComponentFactory"](https://stackoverflow.com/questions/56252142/after-migration-to-androidx-exception-at-start-up-java-lang-classnotfoundexcep) – mike47 Nov 13 '19 at 21:31
  • Probably it happened after upgrade of some libraries (added JUnit and updated Firebase), but after recompilation it disappeared. – CoolMind May 28 '20 at 07:34
  • A picture is worth of 1000 words---Here are the details solution works in my case maybe yours too-- [Before error](https://i.stack.imgur.com/vDEoZ.png) [After fix](https://i.stack.imgur.com/P7F0p.png) – Abhimanyu Kumar Roy Aug 17 '20 at 05:53

17 Answers17

41

Adding Java 1.8 compatibility to my module-level build.gradle fixed this for me (non-release build with multidex enabled).

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
    jvmTarget = "1.8"
}

Unfortunately I'm not sure why :)

Ky -
  • 30,724
  • 51
  • 192
  • 308
Tom
  • 6,946
  • 2
  • 47
  • 63
17

This error message is caused on API level 28+ by:
AppComponentFactory extends android.app.AppComponentFactory

This means that on API 28+ one can use tools:remove ...

tools:remove="android:appComponentFactory"
tools:targetApi="p"
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
8

In my case, the code works on one of my teammates' machine. These steps made it work for me too:

  1. Close project
  2. Remove the project from the list in the welcome screen
  3. Open the project again

This is a solution to another problem, that I also found here in SO. It's worth a try when Invalidate and Restart doesn't solve it for you.

Aguragorn
  • 585
  • 6
  • 14
  • 3
    Wow. Can't believe that solved my problem. It's also solved the problem of the debugger disconnecting a second after it hit a breakpoint. – bickster Aug 01 '20 at 15:11
4

It may sound totally unrelated, but I have seen this problem also when by mistake I have overridden wrong on Activity#onCreate() method i.e.

public void onCreate(@Nullable Bundle savedInstanceState,
        @Nullable PersistableBundle persistentState)

Instead of

protected void onCreate(@Nullable Bundle savedInstanceState)

So, please check that also. The second one is the one that you probably need.

Please refer to documentation for the details of these two methods.

Tomasz
  • 71
  • 4
  • 1
    It seems to have been the answer of @Tomasz but then I add to `File > Sync Project with Gradle Files` to get it working. For interested ones, I found `Sync project with Gradle before building, if needed` in `Settings > Build, Execution, Deployment > Compiler`. – eytienne Mar 19 '21 at 14:20
2

Seems to be a bug, check the next link in the issue tracker:

https://issuetracker.google.com/issues/137646829

PerracoLabs
  • 16,449
  • 15
  • 74
  • 127
1

See java.lang.ClassNotFoundException: Didn't find class "com.my_app_name.androidx".

Remove from AndroidManifest:

<application
    ...
    android:appComponentFactory="androidx"
    tools:replace="android:appComponentFactory"
>

These lines appeared a year ago after migrating to AndroidX. I removed them, now it doesn't show the exception.

CoolMind
  • 26,736
  • 15
  • 188
  • 224
1

If you are using an emulator, try the wipe data option. This worked for me.

1

For Xamarin folks running into this problem: I started to see this problem when upgrading from Xamarin.Forms 4.x to 5.0. With AndroidX changes that I wasn't aware when I've done the upgrade the min SDK version needs to be changed to 29 on the android manifest file, something like: <uses-sdk android:minSdkVersion="29" android:targetSdkVersion="30" />

Carla Camargo
  • 574
  • 5
  • 14
1

For anyone facing the same problem in the multi-Module project:-> In my case I had a multi-module project using the Jetpack compose for the presentation layer

  1. Just Clean the project
  2. Rebuild it
  3. Then again run the project
Devrath
  • 42,072
  • 54
  • 195
  • 297
0

In my case, I was using a library that has an interface that was inheriting a View.OnClickListener interface.

Kristy Welsh
  • 7,828
  • 12
  • 64
  • 106
  • Could you expand on why this is relevant? I think it would be quite common for classes to inherit View.OnClickListener - if so, is there a work around without having to stop inheriting this class? – JCutting8 Mar 02 '22 at 19:43
0

This error can be caused due to using both androidx and legacy android support libraries

Just open project structure and go to Dependencies and select All Modules and check is there any library which contains android.support

Just replace that with androidx version for that library

In the latest versions of android studio, just REMOVE these lines if it is there inside the manifest file

<application
...
tools:replace="android:appComponentFactory"  // REMOVE THIS
android:appComponentFactory="androidx"       // REMOVE THIS
>

If still there is issue check this

https://stackoverflow.com/a/74523286/6236959

0

in my case @AndroidEntryPoint was missing

Samad
  • 1,776
  • 2
  • 20
  • 35
-2

In my case ,that was because of a little mistake in one of my layouts.

I removed one > at the end of a view tag accidentlly.

Check your

xml

files.

Zima
  • 156
  • 2
  • 14
-2

After reviewing the Android Issue Tracker bug report mentioned previously, I saw a mention about multidex support. I had no multidex flags specified in my project, so I tried setting the flag to false on all modules in my project, and the exception went away.

This was not a permanent solution; the problem returned a few builds later.

mike47
  • 2,217
  • 1
  • 27
  • 50
-3

add below code to gradle.properties

android.enableJetifier=true
android.useAndroidX=true

or you can choose migrate to androidX in refactor -> Migrate to androidX.

-3

In my case, add android.enableR8=false in the gradle.properties.

jack
  • 416
  • 4
  • 5
-7

did u create fragments? ok if you create fragments with classes and after that you have to create a class to call those fragments. and if you use switch this cane be like this

`public Fragment getItem(int i) {

    // you have create a switch to get positions using i.
    switch (i) {
        case 0:
            ChatsFragment chatsFragment = new ChatsFragment();
            return chatsFragment;

        case 1:
            GroupsFragment groupsFragment = new GroupsFragment();
            return groupsFragment;

        case 2:
            ContactsFragment contactsFragment = new ContactsFragment();
            return contactsFragment;
        default:
            return null;
    }

}

@Override
public int getCount() {
    return 3;//error can be happen if u use default 0, use fragment counts in here.
}`

in this case you can see 3 cases in switch and the public int getCount() the return value should be 3 not default value 0.

See your error must be close to this one. i got same kind of error and i solved it.

HeshanHH
  • 653
  • 7
  • 9