Permalink
Branch: master
Find file Copy path
4d44a29 Jan 11, 2019
quinnhzchen update readme
0 contributors

Users who have contributed to this file

110 lines (72 sloc) 2.77 KB

Hunter-Debug

English

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

Hugo Hunter-Debug
支持kotlin no yes
自定义logger no yes
对象输出toString no yes
编译速度 一般

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

License

Copyright 2018 Quinn Chen

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.