Stetho调试Android应用

来源:互联网 发布:粤语网络词 编辑:程序博客网 时间:2024/05/16 05:15

Stetho是一个Android应用的调试工具。当你的应用集成Stetho时,开发者可以访问Chrome,在Chrome Developer Tools中查看应用布局,网络请求,sqlite,preference等等,可视化一切应用操作(更重要的是不用root)。

1. 添加依赖

这里我使用的网络框架是okhttp,如果用的其他,要引入其他的依赖库

具体看这里:https://github.com/facebook/stetho

dependencies {    compile 'com.facebook.stetho:stetho:1.5.0'    compile 'com.facebook.stetho:stetho-okhttp3:1.5.0'}

2. 在Application中初始化

   Stetho.initializeWithDefaults(this);

3. 网络调试需要添加interceptor(可选)

addNetworkInterceptor(new StethoInterceptor())

OkHttpClient.Builder builder = new OkHttpClient.Builder()                .addNetworkInterceptor(new StethoInterceptor())                .connectTimeout(20, TimeUnit.SECONDS)                .writeTimeout(10, TimeUnit.SECONDS)                .readTimeout(10, TimeUnit.SECONDS);

4. 运行项目,然后在chrome中访问 chrome://inspect,

这里写图片描述

说明:这里需要翻墙哦!

5. 找到你的项目,点击inspect就可以看到项目相关的东西了。

这里写图片描述