Java 没有找到类“androidx.core.app.CoreComponentFactory”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/57700486/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 01:19:14  来源:igfitidea点击:

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

javaandroid

提问by Chris911

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 :

我在 gradle 应用程序中的依赖项:

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'

回答by MohammadMahdi heidary

add below code to gradle.properties

将下面的代码添加到 gradle.properties

android.enableJetifier=true
android.useAndroidX=true

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

或者您可以在重构中选择迁移到 androidX -> 迁移到 androidX。

回答by HeshanHH

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

你创造了碎片吗?好的,如果您使用类创建片段,然后您必须创建一个类来调用这些片段。如果你使用 switch 这个手杖就像这样

`public Fragment getItem(int i) {

`公共片段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 switchand the public int getCount()the return value should be 3not default value 0.

在这种情况下,您可以在switchpublic int getCount() 中看到 3 种情况,返回值应该是3而不是默认值 0

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

看你的错误一定接近这个。我遇到了同样的错误,我解决了。

回答by Zima

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

xml

files.

文件。

回答by PerracoLabs

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

似乎是一个错误,请检查问题跟踪器中的下一个链接:

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

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

回答by mike47

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 falseon all modules in my project, and the exception went away.

在查看了之前提到的 Android Issue Tracker 错误报告后,我看到了关于 multidex 支持的提及。我的项目中没有指定 multidex 标志,所以我尝试false在我的项目中的所有模块上设置标志,异常消失了。

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

这不是一个永久的解决方案。问题在几次构建后返回。

回答by Tom

Adding Java 1.8 compatibility to my build.gradlefixed this for me (non-release build with multidex enabled).

将 Java 1.8 兼容性添加到我build.gradle为我解决的问题(启用了 multidex 的非发布版本)。

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

Unfortunately I'm not sure why :)

不幸的是我不知道为什么:)

回答by Hyman

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

就我而言,添加android.enableR8=falsegradle.properties。

回答by Tomasz

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.

这听起来可能完全无关,但我也看到了这个问题,因为我错误地在 Activity#onCreate() 方法上覆盖了错误,即

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 the documentations for the details of these two methods.

关于这两种方法的详细信息,请参阅文档。

回答by Aguragorn

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
  1. 关闭项目
  2. 从欢迎屏幕的列表中删除项目
  3. 再次打开项目

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

这是另一个问题的解决方案,我也在 SO 中找到了。当Invalidate and Restart不能为您解决问题时,值得一试。