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 远程调试的方式一样)。废话少说,先来看看效果图。

facebook的Android调试工具Stetho介绍_第1张图片

facebook的Android调试工具Stetho介绍_第2张图片

怎么样,是不是看起来很碉堡,尤其是如果你做过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。


你可能感兴趣的:(facebook的Android调试工具Stetho介绍)