1. Hugo
项目地址:https://github.com/JakeWharton/hugo
工程build.gradle:
dependencies {
classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
}
项目build.gradle
apply plugin: 'com.jakewharton.hugo'
1
使用: 在方法体添加 @DebugLog
@DebugLog
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
add(1, 8);
}
@DebugLog
private int add(int a, int b) {
return a + b;
}
输出:
08-25 14:52:43.413 26165-26165/test.xl.com.myapplication V/MainActivity: ⇢ onCreate(savedInstanceState=null)
08-25 14:52:43.490 26165-26165/test.xl.com.myapplication V/MainActivity: ⇢ add(a=1, b=8)
08-25 14:52:43.490 26165-26165/test.xl.com.myapplication V/MainActivity: ⇠ add [0ms] = 9
08-25 14:52:43.490 26165-26165/test.xl.com.myapplication V/MainActivity: ⇠ onCreate [76ms]
2. Stetho
项目地址:https://github.com/facebook/stetho
通过Elements标签查看界面的视图结构。
通过Network标签观察网络请求。
通过Resources标签查看本地数据,比如sqlite数据库,sharepreference等等。同时可以在这里执行sql语句。
通过Console标签,在这里执行js语句,可以在APP上弹出一个Toast。
dumpapp 是linux/mac上使用的命令行工具,可以修改app内部资源,暂时未详细了解。
项目build.gradle
dependencies {
compile 'com.facebook.stetho:stetho:1.5.0'
compile 'com.facebook.stetho:stetho-okhttp3:1.5.0'
}
初始化Stetho:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Stetho.initializeWithDefaults(this);
}
使用:1. 运行工程,在chrom浏览器中输入:
chrome://inspect
点击inspect
例子:查询存储的SP信息
SharedPreferences sp = getSharedPreferences("test", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString("name", "xiaoming");
editor.putInt("age", 20);
editor.putString("sex", "男");
editor.commit();
stetho显示结果:
Logger
项目地址:https://github.com/orhanobut/logger
Logger 提供以下功能:
- 线程的信息
- 类的信息
- 方法的信息
- 将 JSON 文本人性化输出
- 将换行符人性化输出
- 简洁的输出
- 从日志跳转到源码
项目build.grader
compile 'com.orhanobut:logger:2.1.1'