facebook的Android调试工具Stetho介绍

转自 http://www.androidcn.org/topic/552fabaa8ca8a1e07687e999#0-tsina-1-39947-397232819ff9a47a7b7e80a40613cfe1

Stetho是Facebook出品的一个强大的Android调试工具,使用该工具你可以在Chrome Developer Tools查看App的布局,网络请求,sqlite,preference,一切都是可视化的操作,无须自己在去使用adb,也不需要root你的设备。使用的方式很简单,配置好之后,在Chrome地址栏输入chrome://inspect (哈哈,和webview 远程调试的方式一样)。废话少说,先来看看效果图。

inspector-discovery.png

inspector-sqlite.png

inspector-elements.png

inspector-network.png

怎么样,是不是看起来很碉堡,尤其是如果你做过web开发,肯定感觉超级熟悉哈。下面我们就来看看怎么使用这么碉堡的工具。

配置

添加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());

如果你使用了HttpURLConnection,你需要使用StethoURLConnectionManager来帮忙。

更多细节请参考stetho源码中的stetho-sample。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值