您的位置:首页 > 移动开发 > Android开发

Facebook的Android调试工具Stetho

2016-04-21 11:11 363 查看
Stetho是Facebook出品的一个强大的Android调试工具,使用该工具你可以在线查看数据库、布局、网络请求等一切都是可视化布局。你只需要在配置好代码之后在谷歌浏览器中输入 chrome://inspect 就可以(上图)





这很像web开发中的审查元素选项

配置Stetho

添加额外包 gradle引用

compile 'com.facebook.stetho:stetho:1.1.0'


只有stetho库是必须的,想查看网络请求的话,需要使用下面的两个库之一(看你的网络库用的是okhttp还是urlconnection)

compile 'com.facebook.stetho:stetho-okhttp:1.1.0'


或者

compile 'com.facebook.stetho:stetho-urlconnection:1.1.0'


修改代码

public class MyApplication extends Application {
public void onCreate() {
super.onCreate();
Stetho.initialize(
Stetho.newInitializerBuilder(this)
.enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
.enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this))
.build());
}
}


开启网络请求查看若果你使用了okhttp库,参考下面的代码:

OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(new StethoInterceptor());
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息