最近在研究热更,接入美团热更Robust,在打热更包时报错部分如下:
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:56)
Caused by: org.codehaus.groovy.GroovyException: patch method com.uni.hotterrobust.SecondActivity.getString() haven't insert code by Robust.Cannot patch this method, method.signature ()Ljava/lang/String;
at com.meituan.robust.autopatch.ReadAnnotation.addPatchMethodAndModifiedClass(ReadAnnotation.groovy:134)
at com.meituan.robust.autopatch.ReadAnnotation$_scanClassForModifyMethod_closure4.doCall(ReadAnnotation.groovy:85)
at com.meituan.robust.autopatch.ReadAnnotation.scanClassForModifyMethod(ReadAnnotation.groovy:80)
at com.meituan.robust.autopatch.ReadAnnotation$_readAnnotation_closure1.doCall(ReadAnnotation.groovy:36)
截图:
网上有网友提示,在基础包打包前需要在robust.xml配置文件中,设置我们项目需要被插桩的包名或者类名。若没有配置的话,在打补丁包编译时,添加了注解的方法会报此异常。
但是试了没用,说明我不是这个问题导致的。
找了很久一篇文章的提示让我的问题解决:
Robust对一个方法里面只有字段调用的方法的没有插入代码,简单的来说就是这个方法里面都是字段(局部变量和成员变量)的方法,没有方法调用,new操作等,这类方法被我们归类为简单方法,可以在调用这个方法的地方修复这个问题。
我的问题就是:里面的都是局部变量
后改成:new操作,再重新打基础包,再打热更包就正常了。