Stetho

作者: cherishyan | 来源:发表于2017-08-31 10:07 被阅读24次

偶然了解Stetho,尝试加入了Widgets套餐

引入步骤
  • 模块gradle中引入依赖:
  dependencies { 
    compile 'com.facebook.stetho:stetho-okhttp3:1.5.0' 
  } 
  • 如果需要监测网络数据,需要增加依赖(我这里使用的是okhttp3网络框架):
 dependencies { 
    compile 'com.facebook.stetho:stetho-okhttp3:1.5.0' 
  } 

ps:平时都是用Charles抓包的,功能应该都是一样的,主要是能在chrome上使用。

  • application初始化:
public class MyApplication extends Application {
  public void onCreate() {
    super.onCreate();
    Stetho.initializeWithDefaults(this);
  }
}
  • 监测网络时需要在Okhttp中增加网络拦截器:
new OkHttpClient.Builder()
    .addNetworkInterceptor(new StethoInterceptor())
    .build();

当然,如果使用Retrofit,你可以如下构建:

 OkHttpClient client = new OkHttpClient.Builder()
                .addNetworkInterceptor(new StethoInterceptor())
                .build();

        Retrofit retrofit = new Retrofit.Builder()
                .client(client)
                ...
chrome device

点击inspect可以开始查看到相关数据了。查看数据库,这是我觉得最方便的了:

db

意外发现x5内核在chrome上自带调试:

x5

以及布局层级的检查:

view
  • 如果有打开弹出的小窗口白屏的,需要翻墙一下即可。

相关文章

网友评论

      本文标题:Stetho

      本文链接:https://www.haomeiwen.com/subject/vnofjxtx.html