V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
Registering
V2EX  ›  问与答

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

  •  
  •   Registering · 2019-01-11 15:10:41 +08:00 · 798 次点击
    这是一个创建于 1947 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Hunter-Debug

    Hunter-debug 是基于Hunter开发的,灵感来自于 JakeWharton's hugo,不过相比之下,Hunter-debug 有以下优点

    avatar

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

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2729 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 02:18 · PVG 10:18 · LAX 19:18 · JFK 22:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.