Stetho的介绍

Stetho是一款由Facebook推出的Android应用调试工具,可通过Chrome进行调试。主要功能包括查看数据库、网络请求等。支持多种网络库集成,并提供丰富的调试功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

官方地址:http://facebook.github.io/stetho/

GitHub地址:https://github.com/facebook/stetho

Release包下载地址:https://github.com/facebook/stetho/releases

介绍:Stetho是Facebook推出的一款使用Chrome来调试Android Application的工具。最主要的用途:

  1. 查看数据库
  2. 查看网络

 

使用步骤:

一、添加主依赖

  // Gradle dependency on Stetho 
  dependencies { 
    compile 'com.facebook.stetho:stetho:1.5.0' 
  } 

二、添加网络依赖(三选一):

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

or:

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

or:

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

Features

Chrome DevTools

Chrome DevTools

The integration with the Chrome DevTools frontend is implemented using a client/server protocol which the Stetho software provides for your application. Once your application is integrated, simply navigate to chrome://inspect and click "Inspect" to get started!

Network Inspection

Network Inspection

Network inspection is possible with the full spectrum of Chrome Developer Tools features, including image preview, JSON response helpers, and even exporting traces to the HAR format.

Database Inspection

Database Inspection

SQLite databases can be visualized and interactively explored with full read/write capabilities.

View Hierarchy

View Hierarchy

View hierarchy support for ICS (API 15) and up! Lots of goodies such as instances virtually placed in the hierarchy, view highlighting, and the ability to tap on a view to jump to its position in the hierarchy.

dumpapp

dumpapp

Dumpapp extends beyond the DevTools UI features shown above to provide a much more extensible, command-line interface to application components. A default set of plugins is provided, but the real power of dumpapp is the ability to easily create your own!

Javascript Console

Javascript Console

Javascript Console allows for execution of javascript code that can interact with the application or even the Android SDK.

Integrations

Setup

Integrating with Stetho is intended to be seamless and straightforward for most existing Android applications. There is a simple initialization step which occurs in your Application class:

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

This brings up most of the default configuration but does not enable some additional hooks (most notably, network inspection). See below for specific details on individual subsystems.

Enable Network Inspection

If you are using the popular OkHttp library at the 2.2.x+ or 3.x release, you can use the Interceptors system to automatically hook into your existing stack. This is currently the simplest and most straightforward way to enable network inspection.

For OkHttp 2.x

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

For OkHttp 3.x

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

As interceptors can modify the request and response, add the Stetho interceptor after all others to get an accurate view of the network traffic.

If you are using HttpURLConnection, you can use StethoURLConnectionManager to assist with integration though you should be aware that there are some caveats with this approach. In particular, you must explicitly add Accept-Encoding: gzip to the request headers and manually handle compressed responses in order for Stetho to report compressed payload sizes.

See the stetho-sample project for more details.

Custom dumpapp Plugins

Custom plugins are the preferred means of extending the dumpapp system and can be added easily during configuration. Simply replace your configuration step as such:

Stetho.initialize(Stetho.newInitializerBuilder(context)
    .enableDumpapp(new DumperPluginsProvider() {
      @Override
      public Iterable<DumperPlugin> get() {
        return new Stetho.DefaultDumperPluginsBuilder(context)
            .provide(new MyDumperPlugin())
            .finish();
      }
    })
    .enableWebKitInspector(Stetho.defaultInspectorModulesProvider(context))
    .build());
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值