简体   繁体   中英

"Unable to instantiate appComponentFactory" I tried it in many ways, but I get the same error

I keep getting an error when running the app.

Error content.

E/LoadedApk: Unable to instantiate appComponentFactory
    java.lang.ClassNotFoundException: Didn't find class "com.mopius.samsung.cnt.pt2.user.whateverString" on path: DexPathList[[zip file "/data/app/com.mopius.samsung.cnt.pt2.user-DAObBSssK56o1gzvrv8Oog==/base.apk"],nativeLibraryDirectories=[/data/app/com.mopius.samsung.cnt.pt2.user-DAObBSssK56o1gzvrv8Oog==/lib/arm64, /system/lib64, /product/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.LoadedApk.createAppFactory(LoadedApk.java:273)
        at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:896)
        at android.app.LoadedApk.getClassLoader(LoadedApk.java:991)
        at android.app.LoadedApk.getResources(LoadedApk.java:1248)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2618)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2610)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6900)
        at android.app.ActivityThread.access$1700(ActivityThread.java:272)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2064)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:8034)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)

The methods i tried

  1. AndroidManifest.xml Add the line

    tools:replace="android:appComponentFactory" android:appComponentFactory="whateverString"

  2. proguard-rules.pro Add the line

    -keep class androidx.core.app.CoreComponentFactory{*;}

I've tried, but I keep getting the same error. Do you know how to solve it?

I was getting the same error and fixed it by changing
the multidex dependency from support to androidx like this:

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

implementation 'androidx.multidex:multidex:2.0.1'

Don't forget to add this in defaultConfig:

multiDexEnabled true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM