LSPosed / LSPosed

LSPosed Framework
https://lsposed.org
GNU General Public License v3.0
18.06k stars 2.78k forks source link

[Bug] error shown in logcat E/LoadedApk: Unable to instantiate appComponentFactory #1843

Closed test01wrk closed 2 years ago

test01wrk commented 2 years ago

Steps to reproduce/复现步骤

  1. Write a hook module for MIUI updater app(Xiaomi 11, MIUI 12.5.16 stable), and enable the module in LSPosed manager
    
    public class Hook implements IXposedHookLoadPackage {
    @Override
    public void handleLoadPackage(XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
        if (lpparam != null && "com.android.updater".equals(lpparam.packageName)) {
            try {
                XposedHelpers.findAndHookMethod("com.android.updater.UpdateSettingActivity", lpparam.classLoader,
                        "onCreate", Bundle.class,
                        new XC_MethodHook() {
                            @Override
                            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
                                XposedBridge.log("[UpdaterHook] beforeHookedMethod called");
                            }
                        });
            } catch (Exception e) {
                // ignore
                XposedBridge.log("[UpdaterHook] error: " + e.getMessage());
            }
        }
    }
    }
2. when the updater app started, an error log shown in logcat

2022-04-13 19:17:42.533 14919-14919/? E/LoadedApk: Unable to instantiate appComponentFactory java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList[[zip file "/data/app/qfw3rN9GtpRNmthqehol7Q==/com.android.updater-VTzcdabBUUiDuKRpIbE_cQ==/base.apk"],nativeLibraryDirectories=[/data/app/qfw3rN9GtpRNmthqehol7Q==/com.android.updater-VTzcdabBUUiDuKRpIbE_cQ==/lib/arm64, /data/app/~~qfw3rN9GtpRNmthqehol7Q==/com.android.updater-VTzcdabBUUiDuKRpIbE_cQ==/base.apk!/lib/arm64-v8a, /system/priv-app/RtMiCloudSDK/RtMiCloudSDK.apk!/lib/arm64-v8a, /system/lib64, /systemext/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) at android.app.LoadedApk.createAppFactory(LoadedApk.java:262) at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:907) at android.app.LoadedApk.getClassLoader(LoadedApk.java:960) at java.lang.reflect.Method.invoke(Native Method) at org.lsposed.lspd.nativebridge.HookBridge.invokeOriginalMethod(Native Method) at de.robv.android.xposed.XposedBridge$AdditionalHookInfo.callback(Unknown Source:103) at LSPHooker.getClassLoader(Unknown Source:8) at android.app.LoadedApk.getResources(LoadedApk.java:1192) at android.app.ContextImpl.createAppContext(ContextImpl.java:2671) at android.app.ContextImpl.createAppContext(ContextImpl.java:2663) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6716) at java.lang.reflect.Method.invoke(Native Method) at org.lsposed.lspd.nativebridge.HookBridge.invokeOriginalMethod(Native Method) at de.robv.android.xposed.XposedBridge$AdditionalHookInfo.callback(Unknown Source:103) at LSPHooker_.handleBindApplication(Unknown Source:11) at android.app.ActivityThread.access$1400(ActivityThread.java:246) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1946) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:233) at android.app.ActivityThread.main(ActivityThread.java:7892) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)

3. when the module is disabled,  there's no such error log, something's wrong

Similar to [this issue](https://github.com/taichi-framework/TaiChi/issues/1151)

### Expected behaviour/预期行为

no error log in logcat

### Actual behaviour/实际行为

error shown in logcat

### Xposed Module List/Xposed 模块列表

```shell
N/A

Magisk Module List/Magisk 模块列表

N/A

LSPosed version/LSPosed 版本

1.8.1(6499)

Android version/Android 版本

11

Magisk version/Magisk 版本

24.3

Riru version/Riru 版本

N/A

Version requirement/版本要求

Logs/日志

2022-04-13 19:17:42.533 14919-14919/? E/LoadedApk: Unable to instantiate appComponentFactory java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList[[zip file "/data/app/qfw3rN9GtpRNmthqehol7Q==/com.android.updater-VTzcdabBUUiDuKRpIbE_cQ==/base.apk"],nativeLibraryDirectories=[/data/app/qfw3rN9GtpRNmthqehol7Q==/com.android.updater-VTzcdabBUUiDuKRpIbE_cQ==/lib/arm64, /data/app/~~qfw3rN9GtpRNmthqehol7Q==/com.android.updater-VTzcdabBUUiDuKRpIbE_cQ==/base.apk!/lib/arm64-v8a, /system/priv-app/RtMiCloudSDK/RtMiCloudSDK.apk!/lib/arm64-v8a, /system/lib64, /systemext/lib64]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207) at java.lang.ClassLoader.loadClass(ClassLoader.java:379) at java.lang.ClassLoader.loadClass(ClassLoader.java:312) at android.app.LoadedApk.createAppFactory(LoadedApk.java:262) at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:907) at android.app.LoadedApk.getClassLoader(LoadedApk.java:960) at java.lang.reflect.Method.invoke(Native Method) at org.lsposed.lspd.nativebridge.HookBridge.invokeOriginalMethod(Native Method) at de.robv.android.xposed.XposedBridge$AdditionalHookInfo.callback(Unknown Source:103) at LSPHooker.getClassLoader(Unknown Source:8) at android.app.LoadedApk.getResources(LoadedApk.java:1192) at android.app.ContextImpl.createAppContext(ContextImpl.java:2671) at android.app.ContextImpl.createAppContext(ContextImpl.java:2663) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6716) at java.lang.reflect.Method.invoke(Native Method) at org.lsposed.lspd.nativebridge.HookBridge.invokeOriginalMethod(Native Method) at de.robv.android.xposed.XposedBridge$AdditionalHookInfo.callback(Unknown Source:103) at LSPHooker_.handleBindApplication(Unknown Source:11) at android.app.ActivityThread.access$1400(ActivityThread.java:246) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1946) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:233) at android.app.ActivityThread.main(ActivityThread.java:7892) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)

yujincheng08 commented 2 years ago

send /data/app/~~qfw3rN9GtpRNmthqehol7Q==/com.android.updater-VTzcdabBUUiDuKRpIbE_cQ==/base.apk

test01wrk commented 2 years ago

The "/system/app/Updater/Updater.apk" file: updater.apk.zip

2022-04-14 14:14:22.931 11714-11714/? I/LSPosed: Loading xposed for com.android.updater/9802
2022-04-14 14:14:22.935 11714-11714/? I/LSPosed-Bridge: Loading module com.example.testhookmiuiupdater from /data/app/~~Zf2pGhxwMJb69VkQbhmYjw==/com.example.testhookmiuiupdater-MpgEBXMljIYEnUob0F7hqQ==/base.apk
2022-04-14 14:14:22.937 11714-11714/? I/LSPosed-Bridge:   Loading class com.example.testhookmiuiupdater.Hook
2022-04-14 14:14:22.962 11714-11714/? E/LoadedApk: Unable to instantiate appComponentFactory
    java.lang.ClassNotFoundException: Didn't find class "androidx.core.app.CoreComponentFactory" on path: DexPathList[[zip file "/system/app/Updater/Updater.apk"],nativeLibraryDirectories=[/system/app/Updater/lib/arm64, /system/app/Updater/Updater.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64, /system/priv-app/RtMiCloudSDK/RtMiCloudSDK.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at android.app.LoadedApk.createAppFactory(LoadedApk.java:262)
        at android.app.LoadedApk.createOrUpdateClassLoaderLocked(LoadedApk.java:907)
        at android.app.LoadedApk.getClassLoader(LoadedApk.java:960)
        at java.lang.reflect.Method.invoke(Native Method)
        at org.lsposed.lspd.nativebridge.HookBridge.invokeOriginalMethod(Native Method)
        at de.robv.android.xposed.XposedBridge$AdditionalHookInfo.callback(Unknown Source:103)
        at LSPHooker_.getClassLoader(Unknown Source:8)
        at android.app.LoadedApk.getResources(LoadedApk.java:1192)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2671)
        at android.app.ContextImpl.createAppContext(ContextImpl.java:2663)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6716)
        at java.lang.reflect.Method.invoke(Native Method)
        at org.lsposed.lspd.nativebridge.HookBridge.invokeOriginalMethod(Native Method)
        at de.robv.android.xposed.XposedBridge$AdditionalHookInfo.callback(Unknown Source:103)
        at LSPHooker_.handleBindApplication(Unknown Source:11)
        at android.app.ActivityThread.access$1400(ActivityThread.java:246)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1946)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:233)
        at android.app.ActivityThread.main(ActivityThread.java:7892)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)

2022-04-14 14:19:27.582 15825-15825/? W/Linkify.v16: reflect applyLink failed: 
    miui.reflect.NoSuchMethodException: Couldn't find method android/text/util/Linkify.applyLink(Ljava/lang/String;IILandroid/text/Spannable;)V
        at com.miui.internal.os.Native.getMethod(Native Method)
        at miui.reflect.Method.of(Method.java:35)
        at com.miui.internal.variable.v16.Android_Text_Util_Linkify_class.<clinit>(Android_Text_Util_Linkify_class.java:70)
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:454)
        at java.lang.Class.forName(Class.java:379)
        at com.miui.internal.variable.AbsClassFactory.create(AbsClassFactory.java:24)
        at com.miui.internal.variable.Android_Text_Util_Linkify_class$Factory.<init>(Android_Text_Util_Linkify_class.java:40)
        at com.miui.internal.variable.Android_Text_Util_Linkify_class$Factory.<init>(Android_Text_Util_Linkify_class.java:26)
        at com.miui.internal.variable.Android_Text_Util_Linkify_class$Factory$1.createInstance(Android_Text_Util_Linkify_class.java:32)
        at com.miui.internal.variable.Android_Text_Util_Linkify_class$Factory$1.createInstance(Android_Text_Util_Linkify_class.java:29)
        at miui.util.SoftReferenceSingleton.get(SoftReferenceSingleton.java:25)
        at com.miui.internal.variable.Android_Text_Util_Linkify_class$Factory.getInstance(Android_Text_Util_Linkify_class.java:44)
        at com.miui.internal.initialization.OverrideHelper.doInitialize(OverrideHelper.java:37)
        at miui.core.SdkManager.initialize(SdkManager.java:99)
        at java.lang.reflect.Method.invoke(Native Method)
        at c.a.a.e(SourceFile:4)
        at c.a.a.<init>(SourceFile:3)
        at com.android.updater.Application.<init>(SourceFile:1)
        at java.lang.Class.newInstance(Native Method)
        at android.app.AppComponentFactory.instantiateApplication(AppComponentFactory.java:76)
        at android.app.Instrumentation.newApplication(Instrumentation.java:1158)
        at android.app.LoadedApk.makeApplication(LoadedApk.java:1240)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6832)
        at java.lang.reflect.Method.invoke(Native Method)
        at org.lsposed.lspd.nativebridge.HookBridge.invokeOriginalMethod(Native Method)
        at de.robv.android.xposed.XposedBridge$AdditionalHookInfo.callback(Unknown Source:103)
        at LSPHooker_.handleBindApplication(Unknown Source:11)
        at android.app.ActivityThread.access$1400(ActivityThread.java:246)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1946)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:233)
        at android.app.ActivityThread.main(ActivityThread.java:7892)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)

send /data/app/~~qfw3rN9GtpRNmthqehol7Q==/com.android.updater-VTzcdabBUUiDuKRpIbE_cQ==/base.apk

yujincheng08 commented 2 years ago

image This is not a fatal error. It's just a log and it won't crash the app.

yujincheng08 commented 2 years ago

Oh wait, this is because we create the loadedapk ourselves and it may corrupt the default one. Maybe we should take a further look at it.