others-how to solve Unable to instantiate appComponentFactory error in android

Problem

When we run app in android system, sometimes, we get this error in logcat or firebase logs:

2020-11-03 14:08:43.381 5837-5837/? E/LoadedApk: Unable to instantiate appComponentFactory
    java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList[[zip file "/data/app/com.x.w-74I9dfoLlPlwjOBcmBBYXg==/base.apk"],nativeLibraryDirectories=[/data/app/com.x.w-74I9dfoLlPlwjOBcmBBYXg==/lib/arm64, /system/lib64, /system/product/lib64, /hw_product/lib64, /system/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:270)
        at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:920)
        at android.app.LoadedApk.getClassLoader(LoadedApk.java:1015)
        at android.app.LoadedApk.getResources(LoadedApk.java:1264)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2611)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2599)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:7075)
        at android.app.ActivityThread.access$2200(ActivityThread.java:296)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2208)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:213)
        at android.app.ActivityThread.main(ActivityThread.java:8178)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:513)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1101)

CoreComponentFactory is a class in androidx libraries.

Environment

android api level 28+

Solution #1

add this to your

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

to your proguard-rules.pro

Solution #2

add this:

 android.enableR8=false

to your gradle.properties

Solution #3

Install android 9 system to your android studio emulators.

Ok, everything is done.