熟练使用Android调试神器stetho
2019-07-31 本文已影响231人
码上述Andy
1.stetho介绍
stetho是Facebook用户Android网络抓包,H5等调试的工具。
2.stetho功能
网络抓包
查看数据库,SharedPreferences数据
界面UI层级
H5调试
3.stetho接入工程步骤
引入依赖
//stetho依赖
compile 'com.facebook.stetho:stetho:1.5.0'
//网络库依赖
compile 'com.squareup.okhttp3:okhttp:3.9.0'
Application初始化
public class StethoApplication extends Application {
public void onCreate() {
super.onCreate();
Stetho.initializeWithDefaults(this);
}
}
4.stetho接入项目使用
以网络转包和查看数据库为例如下:
打开Chrome浏览器,输入:chrome://inspect/#devices
图。。。
网络抓包
网络抓包需要添加拦截器:StethoInterceptor
OkHttpClient client = new OkHttpClient.Builder()
.addNetworkInterceptor(new StethoInterceptor())
.build();
在Network中可以看到接口的Response,Headers,Cookies等信息。

Response

Cookies

Headers

查看数据库&SP
在Resources栏中可以非常方便的查看到项目中的数据库和SP数据。
