Closed liugang1014 closed 8 years ago
修改了下做个测试发现还是显示bug class,错在哪,没报错。原生demo确实可以修复: 1.修改mainactivity,直接在mainactivity引用BugClass: case R.id.action_test: // LoadBugClass bugClass = new LoadBugClass(); // Toast.makeText(this, "测试调用方法:" + bugClass.getBugString(), Toast.LENGTH_SHORT).show(); Toast.makeText(this, "测试调用方法:" + new BugClass().bug(), Toast.LENGTH_SHORT).show();
break;
2.修改groovy脚本:
public static void process(String buildDir, String lib) { println(lib) ClassPool classes = ClassPool.getDefault() classes.appendClassPath(buildDir) classes.appendClassPath(lib) //下面的操作比较容易理解,在将需要关联的类的构造方法中插入引用代码 CtClass c = classes.getCtClass("dodola.hotfix.BugClass") if (c.isFrozen()) { c.defrost() } println("====添加构造方法====") def constructor = c.getConstructors()[0]; constructor.insertBefore("System.out.println(dodola.hackdex.AntilazyLoad.class);") c.writeFile(buildDir) CtClass c1 = classes.getCtClass("dodola.hotfix.LoadBugClass") if (c1.isFrozen()) { c1.defrost() } println("====添加构造方法====") def constructor1 = c1.getConstructors()[0]; constructor1.insertBefore("System.out.println(dodola.hackdex.AntilazyLoad.class);") c1.writeFile(buildDir)
//此处以下是我自己增加的 CtClass c2 = classes.getCtClass("dodola.hotfix.MainActivity") if (c2.isFrozen()) { c2.defrost() }
def constructor2 = c2.getConstructors()[0]; constructor2.insertBefore("System.out.println(dodola.hackdex.AntilazyLoad.class);") c2.writeFile(buildDir) }
fixed in RocooFix
修改了下做个测试发现还是显示bug class,错在哪,没报错。原生demo确实可以修复: 1.修改mainactivity,直接在mainactivity引用BugClass: case R.id.action_test: // LoadBugClass bugClass = new LoadBugClass(); // Toast.makeText(this, "测试调用方法:" + bugClass.getBugString(), Toast.LENGTH_SHORT).show(); Toast.makeText(this, "测试调用方法:" + new BugClass().bug(), Toast.LENGTH_SHORT).show();
2.修改groovy脚本:
//此处以下是我自己增加的 CtClass c2 = classes.getCtClass("dodola.hotfix.MainActivity") if (c2.isFrozen()) { c2.defrost() }