Didn't find class “androidx.core.app.CoreComponentFactory”

走远了吗. 提交于 2019-12-19 05:14:24

问题


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'

回答1:


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

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




回答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.




回答3:


Adding Java 1.8 compatibility to my 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 :)




回答4:


add below code to gradle.properties

android.enableJetifier=true
android.useAndroidX=true

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




回答5:


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.




回答6:


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.



来源:https://stackoverflow.com/questions/57700486/didnt-find-class-androidx-core-app-corecomponentfactory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!