Meituan-Dianping / Robust

Robust is an Android HotFix solution with high compatibility and high stability. Robust can fix bugs immediately without a reboot.
Apache License 2.0
4.43k stars 809 forks source link

为什么我新增的方法不生效,修复已有的方法是可以的 #388

Open kukulong123 opened 4 years ago

kukulong123 commented 4 years ago

在一个类class MeFragment面新增了一个方法: @Add public void newMethod(){ ToastUtil.show(context,"newMethod新增方法"); System.out.println("newMethod新增方法"); } , 然后再另一个方法里面调用该方法,运行的时候报错日志如下: 03-19 13:46:58.287 16103-16103/ D/robust: arrivied in isSupport ::false:992 paramArrayOfObject [Ljava.lang.Object;@15acb046 03-19 13:46:58.287 16103-16103/ D/robust: in isSupport assemble method number is 992 03-19 13:46:58.287 16103-16103/ D/robust: arrivied in isSupport ::false:992 paramArrayOfObject [Ljava.lang.Object;@15acb046 isSupport result is true 03-19 13:46:58.287 16103-16103/ D/robust: arrivied in AccessDispatch ::false:992 paramArrayOfObject [Ljava.lang.Object;@34609207 03-19 13:46:58.287 16103-16103/ D/robust: keyToValueRelation not contain 03-19 13:46:58.287 16103-16103/ D/robust: assemble method number is 992 03-19 13:46:58.287 16103-16103/ D/robust: invoke method is .robust.MeFragmentPatch.onClick(android.view.View) 03-19 13:46:58.287 16103-16103/ D/robust: invoke method is No: 57 getId 03-19 13:46:58.294 16103-16103/ W/System.err: at com.meituan.robust.utils.EnhancedRobustUtils.invokeReflectMethod(EnhancedRobustUtils.java:34) 03-19 13:46:58.294 16103-16103/ W/System.err: at .robust.MeFragmentPatch.onClick(MeFragmentPatch.java:235) 03-19 13:46:58.294 16103-16103/ W/System.err: at .robust.MeFragmentPatchControl.accessDispatch(PatchTemplate.java) 03-19 13:46:58.294 16103-16103/ W/System.err: at com.meituan.robust.PatchProxy.accessDispatchVoid(PatchProxy.java:113) 03-19 13:46:58.294 16103-16103/ D/robust: invoke method is No: 68 newMethod 03-19 13:46:58.295 16103-16103/ D/robust: get value is context No: 69 03-19 13:46:58.295 16103-16103/ W/System.err: at com.meituan.robust.utils.EnhancedRobustUtils.invokeReflectMethod(EnhancedRobustUtils.java:34) 03-19 13:46:58.295 16103-16103/ W/System.err: at .robust.MeFragmentPatch.onClick(MeFragmentPatch.java:236) 03-19 13:46:58.295 16103-16103/ W/System.err: at .robust.MeFragmentPatchControl.accessDispatch(PatchTemplate.java) 03-19 13:46:58.295 16103-16103/ W/System.err: at com.meituan.robust.PatchProxy.accessDispatchVoid(PatchProxy.java:113) 03-19 13:46:58.295 16103-16103/ D/robust: invoke method is No: 70 newMethod 03-19 13:46:58.295 16103-16103/ D/robust: get value is context No: 71 03-19 13:46:58.295 16103-16103/ D/robust: parameters[] from method No: 72 [Ljava.lang.Object;@32067f34 03-19 13:46:58.295 16103-16103/ D/robust: invoke method is No: 73 getSimpleName 03-19 13:46:58.296 16103-16103/ D/robust: invoke method is No: 74 putExtra 03-19 13:46:58.299 16103-16103/ D/robust: invoke method is No: 75 startActivity

生成的MeFragmentPatch localObject27 = ((MeFragmentPatch)this).originClass; Object[] arrayOfObject25 = new Object[0]; ((String)EnhancedRobustUtils.invokeReflectMethod("newMethod", localObject27, arrayOfObject25, null, MeFragment.class)); Log.d("robust", "invoke method is No: 68 newMethod"); if (!(this instanceof MeFragmentPatch)) break label1460; localObject28 = ((MeFragmentPatch)this).originClass; Context localContext11 = (Context)EnhancedRobustUtils.getFieldValue("context", localObject28, BaseFragment.class); Log.d("robust", "get value is context No: 69"); if (this != this) break label1466; localObject29 = ((MeFragmentPatch)this).originClass; Object[] arrayOfObject26 = new Object[0]; String str4 = (String)EnhancedRobustUtils.invokeReflectMethod("newMethod", localObject29, arrayOfObject26, null, MeFragment.class); Log.d("robust", "invoke method is No: 70 newMethod"); EnhancedRobustUtils.invokeReflectStaticMethod("show", ToastUtil.class, getRealParameter(new Object[] { localContext11, str4 }), new Class[] { Context.class, CharSequence.class }); if (!(this instanceof MeFragmentPatch)) break label1472; localObject30 = ((MeFragmentPatch)this).originClass; Context localContext12 = (Context)EnhancedRobustUtils.getFieldValue("context", localObject30, BaseFragment.class);

发现为啥invoke的是原先的类MeFragment而不是invoke MeFragmentPatch呢 原先的类里肯定没有新增的这个方法newMethod啊,

而MeFragmentPatch中有新增的这个方法:

public String newMethod() { if ((this instanceof MeFragmentPatch

)); for (Object localObject = ((MeFragmentPatch)this).originClass; ; localObject = this) { Context localContext = (Context)EnhancedRobustUtils.getFieldValue("context", localObject, BaseFragment.class); Log.d("robust", "get value is context No: 56"); EnhancedRobustUtils.invokeReflectStaticMethod("show", ToastUtil.class, getRealParameter(new Object[] { localContext, "新增方法" }), new Class[] { Context.class, CharSequence.class }); return "aaaa"; } }

另外吐槽下github的编辑器太难用了,都不能插入截图。

weiyixiong commented 4 years ago

是大写A吧。@Add 看看是不是你引用错了

kukulong123 commented 4 years ago

A 是大写,拷贝过来 这里显示小写了。