Skip to content

Latest commit

 

History

History
125 lines (87 loc) · 3.7 KB

README_hunter_debug_ch.md

File metadata and controls

125 lines (87 loc) · 3.7 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:1.2.0'
}

repositories {
    maven {
        name = "GithubPackages"
        url = uri("https://maven.pkg.github.com/Leaking/Hunter")
        credentials {
            username = 'Leaking'
            password = '\u0067\u0068\u0070\u005f\u0072\u006a\u0041\u004b\u0037\u006d\u0048\u0047\u006b\u0031\u0045\u0039\u0063\u0048\u0044\u0076\u004f\u0039\u0078\u006f\u0046\u0048\u004d\u0049\u0032\u006a\u0047\u0057\u0047\u0068\u0032\u0036\u0065\u0075\u0043\u006b'
        }
    }
}

buildscript {
    repositories {
        maven {
            name = "GithubPackages"
            url = uri("https://maven.pkg.github.com/Leaking/Hunter")
            credentials {
                username = 'Leaking'
                password = '\u0067\u0068\u0070\u005f\u0072\u006a\u0041\u004b\u0037\u006d\u0048\u0047\u006b\u0031\u0045\u0039\u0063\u0048\u0044\u0076\u004f\u0039\u0078\u006f\u0046\u0048\u004d\u0049\u0032\u006a\u0047\u0057\u0047\u0068\u0032\u0036\u0065\u0075\u0043\u006b'
            }
        }
        google()
    }
    dependencies {
        classpath 'com.quinn.hunter:hunter-debug-plugin:1.2.0'
        classpath 'com.quinn.hunter:hunter-transform:1.2.0'
    }
}

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.