非死book的Android調試工具Stetho介紹
Stetho是非死book出品的一個強大的Android調試工具,使用該工具你可以在Chrome Developer Tools查看App的布局,網絡請求,sqlite,preference,一切都是可視化的操作,無須自己在去使用adb,也不需要root你的設備。使用的方式很簡單,配置好之后,在Chrome地址欄輸入chrome://inspect (哈哈,和webview 遠程調試的方式一樣)。廢話少說,先來看看效果圖。
怎么樣,是不是看起來很碉堡,尤其是如果你做過web開發,肯定感覺超級熟悉哈。下面我們就來看看怎么使用這么碉堡的工具。
配置
添加gradle引用
compile 'com.非死book.stetho:stetho:1.1.0'
只有stetho庫是必須的,想查看網絡請求的話,需要使用下面的兩個庫之一(看你的網絡庫用的是okhttp還是urlconnection)
compile 'com.非死book.stetho:stetho-okhttp:1.1.0'
或者
compile 'com.非死book.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。
來自:http://www.androidcn.org/topic/552fabaa8ca8a1e07687e999
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!