Open 670832188 opened 4 years ago
在修改的方法中引用已知类,出现ClassNotFoundException,示例代码如下: 修复前: private void robustAddMethod() { Log.e("mytag", "robustAddMethod"); } 修复后: @Modify private void robustAddMethod() { Log.e("mytag", "robustAddMethod"); Glide.with(this); showToast("新增showToast方法: " + Process.myPid() + " " + Glide.with(this).toString()); }
问题的关键在于,引用的类并不是新增类,但是这个类如果是我们自己写的,则可以通过把类标记为新增类来解决,但是引用的是第三方的类就没有办法了。
异常类型:app运行时异常
手机型号:所有
手机系统版本:Android P Robust版本:如:0.4.99
Gradle版本:3.5.3
系统:如:Windows
堆栈/日志:
2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/bumptech/glide/Glide; 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at com.cy.hotfix.test.RobustTestActivityPatch.robustModifyMethod(RobustTestActivityPatch.java:63) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at com.cy.hotfix.test.RobustTestActivityPatch.RobustPublicrobustModifyMethod(Unknown Source:0) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at com.cy.hotfix.test.RobustTestActivityPatchControl.accessDispatch(Unknown Source:91) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at com.meituan.robust.PatchProxy.accessDispatch(:94) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at com.meituan.robust.PatchProxy.proxy(:44) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at com.cy.hotfix.test.activity.RobustTestActivity.s(Unknown Source:13) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at com.cy.hotfix.test.activity.RobustTestActivity.onClick(:38) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at android.view.View.performClick(View.java:7247) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at android.view.View.performClickInternal(View.java:7224) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at android.view.View.access$3500(View.java:819) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at android.view.View$PerformClick.run(View.java:27551) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at android.os.Handler.handleCallback(Handler.java:914) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at android.os.Handler.dispatchMessage(Handler.java:100) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at android.os.Looper.loop(Looper.java:225) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at android.app.ActivityThread.main(ActivityThread.java:7594) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at java.lang.reflect.Method.invoke(Native Method) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950) 2020-07-01 12:07:43.843 32384-32384/com.cy.hotfix.test.robust W/System.err: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.bumptech.glide.Glide" on path: DexPathList[[zip file "/data/user/0/com.cy.hotfix.test.robust/cache/patches/patch_temp.jar"],nativeLibraryDirectories=[/system/lib64, /system/product/lib64]] 2020-07-01 12:07:43.843 32384-32384/com.cy.hotfix.test.robust W/System.err: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:230) 2020-07-01 12:07:43.843 32384-32384/com.cy.hotfix.test.robust W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:379) 2020-07-01 12:07:43.843 32384-32384/com.cy.hotfix.test.robust W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:312) 2020-07-01 12:07:43.843 32384-32384/com.cy.hotfix.test.robust W/System.err: ... 18 more
可以手动将这个类放到新补丁dex中 (1)将含有这个类的APK变成smali,找到这个glide类的smali (2)将补丁dex/apk变成smali (3)将(1)&(2)的smali文件合并,一起smali to dex,就得到了预期补丁
在修改的方法中引用已知类,出现ClassNotFoundException,示例代码如下: 修复前: private void robustAddMethod() { Log.e("mytag", "robustAddMethod"); } 修复后: @Modify private void robustAddMethod() { Log.e("mytag", "robustAddMethod"); Glide.with(this); showToast("新增showToast方法: " + Process.myPid() + " " + Glide.with(this).toString()); }
问题的关键在于,引用的类并不是新增类,但是这个类如果是我们自己写的,则可以通过把类标记为新增类来解决,但是引用的是第三方的类就没有办法了。
异常类型:app运行时异常
手机型号:所有
手机系统版本:Android P Robust版本:如:0.4.99
Gradle版本:3.5.3
系统:如:Windows
堆栈/日志:
2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/bumptech/glide/Glide; 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at com.cy.hotfix.test.RobustTestActivityPatch.robustModifyMethod(RobustTestActivityPatch.java:63) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at com.cy.hotfix.test.RobustTestActivityPatch.RobustPublicrobustModifyMethod(Unknown Source:0) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at com.cy.hotfix.test.RobustTestActivityPatchControl.accessDispatch(Unknown Source:91) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at com.meituan.robust.PatchProxy.accessDispatch(:94) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at com.meituan.robust.PatchProxy.proxy(:44) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at com.cy.hotfix.test.activity.RobustTestActivity.s(Unknown Source:13) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at com.cy.hotfix.test.activity.RobustTestActivity.onClick(:38) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at android.view.View.performClick(View.java:7247) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at android.view.View.performClickInternal(View.java:7224) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at android.view.View.access$3500(View.java:819) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at android.view.View$PerformClick.run(View.java:27551) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at android.os.Handler.handleCallback(Handler.java:914) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at android.os.Handler.dispatchMessage(Handler.java:100) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at android.os.Looper.loop(Looper.java:225) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at android.app.ActivityThread.main(ActivityThread.java:7594) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at java.lang.reflect.Method.invoke(Native Method) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539) 2020-07-01 12:07:43.842 32384-32384/com.cy.hotfix.test.robust W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950) 2020-07-01 12:07:43.843 32384-32384/com.cy.hotfix.test.robust W/System.err: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.bumptech.glide.Glide" on path: DexPathList[[zip file "/data/user/0/com.cy.hotfix.test.robust/cache/patches/patch_temp.jar"],nativeLibraryDirectories=[/system/lib64, /system/product/lib64]] 2020-07-01 12:07:43.843 32384-32384/com.cy.hotfix.test.robust W/System.err: at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:230) 2020-07-01 12:07:43.843 32384-32384/com.cy.hotfix.test.robust W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:379) 2020-07-01 12:07:43.843 32384-32384/com.cy.hotfix.test.robust W/System.err: at java.lang.ClassLoader.loadClass(ClassLoader.java:312) 2020-07-01 12:07:43.843 32384-32384/com.cy.hotfix.test.robust W/System.err: ... 18 more