Hunter-debug 是基于Hunter开发的,灵感来自于 JakeWharton's hugo,不过相比之下,Hunter-debug 有以下优点
Hunter-Debug 是用 ASM 修改字节码,而非使用 AspectJ,所以自然会更快。
在 build.gradle 中添加以下依赖
dependencies {
implementation 'com.quinn.hunter:hunter-debug-library:0.9.4'
}
repositories {
jcenter()
}
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.quinn.hunter:hunter-debug-plugin:0.9.5'
}
}
apply plugin: 'hunter-debug'
在某个方法开头添加注解 @HunterDebug,就会打印方法参数,以及方法返回值,还有方法耗时。
比如
@HunterDebug
private String appendIntAndString(int a, String b) {
SystemClock.sleep(100);
return a + " " + b;
}
MainActivity: ⇢ appendIntAndString[a="5", b="billions"]
⇠ appendIntAndString[0ms]="5 billions"
如果你想将输出结果使用你们项目中自定义的 logger 处理,可以使用
@HunterDebugImpl
,然后设置一个接受日志输出的HunterLoggerHandler
HunterLoggerHandler.installLogImpl(new HunterLoggerHandler(){
@Override
protected void log(String tag, String msg) {
//you can use your custom logger here
YourLog.i(tag, msg);
}
});
如果你只想在 debug 模式下使用该插件,则可以这样设置,
debugHunterExt {
runVariant = 'DEBUG' //'DEBUG', 'RELEASE', 'ALWAYS', 'NEVER', The 'ALWAYS' is default value
}
欢迎引入 Hunter-Debug 到你项目中使用,使用过程有遇到什么问题,或者有什么建议,都可以提 issue 或者邮件联系我,只要有空我会第一时间回应。