用 ASM 写了一个类似 JakeWharton 的 hugo 的插件,解决了 hugo 存在的一些问题

2019-01-11 15:10:41 +08:00
 Registering

Hunter-Debug

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 或者邮件联系我,只要有空我会第一时间回应。

799 次点击
所在节点    问与答
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/526062

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX