android网络调试工具Stetho介绍

来源:互联网 发布:咫尺网络微官网 编辑:程序博客网 时间:2024/06/05 23:39

背景

以前我们在开发过程中一直使用的是vpn代理抓包的方法,来处理后端哥们在调试过程中的数据问题,但前段时间公司网络调整,代理不能用了,很是莫名奇妙。。。。没办法,只能另辟蹊径,在网上查找发现还真有一款很不错的工具,那就是我今天给大家介绍的工具Stetho,这是有facebook出品的一款开源工具,源码https://github.com/facebook/stetho,很好,很强大,跟web的浏览器开发工具差不多,本篇主要讲如何接入

使用前提

要翻墙,要翻墙,要翻墙,重要的事说三遍,不然当你打开chrome的时候就会发现一片空白(具体方法下面讲),这点很坑。

接入Stetho

第一步:

grade接入

compile 'com.facebook.stetho:stetho:1.5.0'

compile ‘com.facebook.stetho:stetho:1.5.0’

Maven接入

<dependency>  <groupId>com.facebook.stetho</groupId>  <artifactId>stetho</artifactId>  <version>1.5.0</version></dependency>

第二步

使用okhttp作为网络请求的基础库

compile 'com.facebook.stetho:stetho-okhttp3:1.5.0'

第三步 初始化 Stetho

在Application中加入

public class MyApplication extends Application {  public void onCreate() {    super.onCreate();    Stetho.initializeWithDefaults(this);  }}

使用okhttp3.x

new OkHttpClient.Builder()    .addNetworkInterceptor(new StethoInterceptor())    .build()

使用okhttp2.x

OkHttpClient client = new OkHttpClient();client.networkInterceptors().add(new StethoInterceptor());

最后chrome联调

连接数据线,注意必须连接数据线,启动你的程序,在chrome上输入chrome://inspect,你就会得到一片空白,如下图:

这里写图片描述
在点击inspect进入调试界面,记住一定要翻墙,不然你就会得到如下的界面:
这里写图片描述

原创粉丝点击