简介

Stetho是Facebook推出的Android应用程序的调试桥,可启用功能强大的Chrome进行调试

使用

导入依赖

1
2
3
debugImplementation 'com.facebook.stetho:stetho:1.5.1'
debugImplementation 'com.facebook.stetho:stetho-okhttp3:1.5.1'
debugImplementation 'com.facebook.stetho:stetho-urlconnection:1.5.1'

在Application中初始化

1
2
3
4
5
6
7
if (BuildConfig.DEBUG) {
Stetho.initialize(
newInitializerBuilder(this)
.enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
.enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this))
.build());
}

增加网络请求拦截器(addNetworkInterceptor)

1
2
3
4
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(initLog())
.addNetworkInterceptor(new StethoInterceptor())
.build();

Chrome地址栏输入 chrome://inspect

Remote Target中会出现正在连接的APP,点击 inspect 进入调试界面

注意事项

首次进入调试界面需要翻墙