rovo89 / XposedBridge

The Java part of the Xposed framework.
3.91k stars 1.1k forks source link

ClassNotFound 4.4 #60

Closed Mikanoshi closed 9 years ago

Mikanoshi commented 9 years ago

I started receiving many bug reports about my module causing Sense Home launcher crashes after its last update. Xposed cannot find some classes anymore, but they are certainly there and are public. This happens only on 4.4.x ROMs and all classes are from the classes2.dex so far, even if parent class is in classes.dex, some of its inner classes are in second dex and cannot be hooked.

APK: http://www.apkmirror.com/apk/htc-corporation/sense-home/sense-home-7-20-599309-2-android-apk-download/

Errors:

de.robv.android.xposed.XposedHelpers$ClassNotFoundError: java.lang.ClassNotFoundException: com.htc.launcher.LauncherAppWidgetHostView
    at de.robv.android.xposed.XposedHelpers.findClass(XposedHelpers.java:52)
    at de.robv.android.xposed.XposedHelpers.findAndHookMethod(XposedHelpers.java:136)
    at com.sensetoolbox.six.mods.PrismMods.execHook_InvisiWidget(PrismMods.java:110)
    at com.sensetoolbox.six.mods.XMain.handleLoadPackage(XMain.java:442)
    at de.robv.android.xposed.IXposedHookLoadPackage$Wrapper.handleLoadPackage(IXposedHookLoadPackage.java:20)
    at de.robv.android.xposed.callbacks.XC_LoadPackage.call(XC_LoadPackage.java:34)
    at de.robv.android.xposed.callbacks.XCallback.callAll(XCallback.java:70)
    at de.robv.android.xposed.XposedBridge$1.beforeHookedMethod(XposedBridge.java:208)
    at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:611)
    at android.app.ActivityThread.handleBindApplication(Native Method)
    at android.app.ActivityThread.access$1500(ActivityThread.java:156)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1418)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:157)
    at android.app.ActivityThread.main(ActivityThread.java:5872)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:852)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:668)
    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.htc.launcher.LauncherAppWidgetHostView
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:251)
    at external.org.apache.commons.lang3.ClassUtils.getClass(ClassUtils.java:823)
    at de.robv.android.xposed.XposedHelpers.findClass(XposedHelpers.java:50)
    ... 20 more
Caused by: java.lang.NoClassDefFoundError: com/htc/launcher/LauncherAppWidgetHostView
    ... 24 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.htc.launcher.LauncherAppWidgetHostView" on path: DexPathList[[zip file "/data/app/com.htc.launcher-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.htc.launcher-2, /vendor/lib, /system/lib, /vendor/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
    ... 24 more
de.robv.android.xposed.XposedHelpers$ClassNotFoundError: java.lang.ClassNotFoundException: com.htc.launcher.pageview.AllAppsDialogFragment.OnOptionClickListener
    at de.robv.android.xposed.XposedHelpers.findClass(XposedHelpers.java:52)
    at com.sensetoolbox.six.mods.PrismMods.execHook_AppDrawerGridSizes(PrismMods.java:461)
    at com.sensetoolbox.six.mods.XMain.handleLoadPackage(XMain.java:459)
    at de.robv.android.xposed.IXposedHookLoadPackage$Wrapper.handleLoadPackage(IXposedHookLoadPackage.java:20)
    at de.robv.android.xposed.callbacks.XC_LoadPackage.call(XC_LoadPackage.java:34)
    at de.robv.android.xposed.callbacks.XCallback.callAll(XCallback.java:70)
    at de.robv.android.xposed.XposedBridge$1.beforeHookedMethod(XposedBridge.java:208)
    at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:611)
    at android.app.ActivityThread.handleBindApplication(Native Method)
    at android.app.ActivityThread.access$1500(ActivityThread.java:156)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1418)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:157)
    at android.app.ActivityThread.main(ActivityThread.java:5867)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.htc.launcher.pageview.AllAppsDialogFragment.OnOptionClickListener
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:251)
    at external.org.apache.commons.lang3.ClassUtils.getClass(ClassUtils.java:823)
    at de.robv.android.xposed.XposedHelpers.findClass(XposedHelpers.java:50)
    ... 19 more
Caused by: java.lang.NoClassDefFoundError: com/htc/launcher/pageview/AllAppsDialogFragment/OnOptionClickListener
    ... 23 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.htc.launcher.pageview.AllAppsDialogFragment.OnOptionClickListener" on path: DexPathList[[zip file "/data/app/com.htc.launcher-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.htc.launcher-2, /vendor/lib, /system/lib, /vendor/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
    ... 23 more
de.robv.android.xposed.XposedHelpers$ClassNotFoundError: java.lang.ClassNotFoundException: com.htc.launcher.folder.Folder.FolderDataManager
    at de.robv.android.xposed.XposedHelpers.findClass(XposedHelpers.java:52)
    at com.sensetoolbox.six.mods.PrismMods.execHook_LauncherLock(PrismMods.java:1065)
    at com.sensetoolbox.six.mods.XMain.handleLoadPackage(XMain.java:469)
    at de.robv.android.xposed.IXposedHookLoadPackage$Wrapper.handleLoadPackage(IXposedHookLoadPackage.java:20)
    at de.robv.android.xposed.callbacks.XC_LoadPackage.call(XC_LoadPackage.java:34)
    at de.robv.android.xposed.callbacks.XCallback.callAll(XCallback.java:70)
    at de.robv.android.xposed.XposedBridge$1.beforeHookedMethod(XposedBridge.java:208)
    at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:611)
    at android.app.ActivityThread.handleBindApplication(Native Method)
    at android.app.ActivityThread.access$1500(ActivityThread.java:156)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1418)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:157)
    at android.app.ActivityThread.main(ActivityThread.java:5867)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassNotFoundException: com.htc.launcher.folder.Folder.FolderDataManager
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:251)
    at external.org.apache.commons.lang3.ClassUtils.getClass(ClassUtils.java:823)
    at de.robv.android.xposed.XposedHelpers.findClass(XposedHelpers.java:50)
    ... 19 more
Caused by: java.lang.NoClassDefFoundError: com/htc/launcher/folder/Folder/FolderDataManager
    ... 23 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.htc.launcher.folder.Folder.FolderDataManager" on path: DexPathList[[zip file "/data/app/com.htc.launcher-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.htc.launcher-2, /vendor/lib, /system/lib, /vendor/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
    ... 23 more

Also some class verification error:

java.lang.VerifyError: com/htc/launcher/folder/Folder
    at java.lang.Class.getDeclaredConstructors(Native Method)
    at java.lang.Class.getDeclaredConstructors(Class.java:574)
    at de.robv.android.xposed.XposedBridge.hookAllConstructors(XposedBridge.java:570)
    at com.sensetoolbox.six.mods.PrismMods.execHook_20Folder_code(PrismMods.java:236)
    at com.sensetoolbox.six.mods.XMain.handleLoadPackage(XMain.java:447)
    at de.robv.android.xposed.IXposedHookLoadPackage$Wrapper.handleLoadPackage(IXposedHookLoadPackage.java:20)
    at de.robv.android.xposed.callbacks.XC_LoadPackage.call(XC_LoadPackage.java:34)
    at de.robv.android.xposed.callbacks.XCallback.callAll(XCallback.java:70)
    at de.robv.android.xposed.XposedBridge$1.beforeHookedMethod(XposedBridge.java:208)
    at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:611)
    at android.app.ActivityThread.handleBindApplication(Native Method)
    at android.app.ActivityThread.access$1500(ActivityThread.java:156)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1418)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:157)
    at android.app.ActivityThread.main(ActivityThread.java:5867)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:674)
    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
    at dalvik.system.NativeStart.main(Native Method)
rsteckler commented 9 years ago

I had the same issue a long time ago. Here's the thread and the solution: http://forum.xda-developers.com/xposed/loading-class-classes2-dex-t2852950

Mikanoshi commented 9 years ago

It's more like a workaround, too complicated for a problem that happens only on android 4.4 with a single apk. Why everything is working on Lollipop? Maybe v54 framework is missing something regarding to multidex?

rovo89 commented 9 years ago

This is a duplicate of #30. I would rather hook Application.attach(): https://github.com/rovo89/XposedBridge/issues/30#issuecomment-68488797

Why everything is working on Lollipop?

Because ART supports multidex files. Dalvik does not. When the application starts, the class loader only knows the classes in classes.dex. The Xposed callback fires as early as possible, and therefore at the time you try to place the hook, the class is not there and you get those exceptions. Later, the application uses a support library to extract the classes2.dex file from the APK and make it known to the class loader.

I see no good way of handling multdex APKs on Dalvik automatically, so you'll have to place the hooks later as mentioned in the solutions you were linked to.

By the way, Facebook does (or did?) something very similar. There might be other apps with their own implementation as well. Xposed is just using the system's way to retrieve a class from a class loader - and if that class doesn't exist at that time, it can't be found.

Grohden commented 8 years ago

Had same error here, i don't know why,manifest: targetapi and compilesdkversion 23, my phone is running 5.1.1, so it should work, but it doesn't work, then i changed the minsdkversion to 10 and worked, i think my problem is on android studio 2.x , something with instant run, anyone can explain me the reason or give me a workaround to use minsdkversion 18 again?

rovo89 commented 8 years ago

@Grohden Why do you think that your issue is the same? The error above happens on Android 4.4 and below, your device is 5.1.1. This issue has nothing to do with the minsdkversion. Please open a separate issue if you have the impression that you're running into an Xposed issue and clearly state what the issue is. Also 5.1.1 is SDK22: https://source.android.com/source/build-numbers.html