stetho README

The project's README from github.com/facebook/stetho. As one markdown file: README.md.

Stetho Build Status

Stetho is a sophisticated debug bridge for Android applications. When enabled, developers have access to the Chrome Developer Tools feature natively part of the Chrome desktop browser. Developers can also choose to enable the optional dumpapp tool which offers a powerful command-line interface to application internals.

Once you complete the set-up instructions below, just start your app and point your laptop browser to chrome://inspect. Click the "Inspect" button to begin.

Set-up

Download

Download the latest JARs or grab via Gradle:

implementation 'com.facebook.stetho:stetho:1.6.0'

or Maven:

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

Only the main stetho dependency is strictly required; however, you may also wish to use one of the network helpers:

implementation 'com.facebook.stetho:stetho-okhttp3:1.6.0'

or:

implementation 'com.facebook.stetho:stetho-urlconnection:1.6.0'

You can also enable a JavaScript console with:

implementation 'com.facebook.stetho:stetho-js-rhino:1.6.0'

For more details on how to customize the JavaScript runtime see stetho-js-rhino.

Putting it together

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);
  }
}

Also ensure that your MyApplication Java class is registered in your AndroidManifest.xml file, otherwise you will not see an "Inspect" button in chrome://inspect/#devices :

<manifest
        xmlns:android="http://schemas.android.com/apk/res/android"
        ...>
        <application
                android:name="MyApplication"
                ...>
         </application>
</manifest>                

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 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:

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

Note that okhttp 2.x will work as well, but with slightly different syntax and you must use the stetho-okhttp artifact (not stetho-okhttp3).

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.

Going further

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())

See the stetho-sample project for more details.

Improve Stetho!

See the CONTRIBUTING.md file for how to help out.

License

Stetho is MIT-licensed. See LICENSE file for more details.

stetho (facebook/stetho)

Searching Database…

12.6K ·GitHub
archived
What is this?Stetho is a debug bridge for Android apps that lets you inspect your running app using Chrome's Developer Tools, plus an optional command-line tool called dumpapp for poking at app internals.
Is this a library I add to my app, or a standalone tool?It is a Java library you integrate into your Android app via Gradle or Maven; once included, you inspect your running app from the Chrome browser on your laptop.
How do I add it to my Android project?Add the stetho dependency via Gradle or Maven, call the initialization step in your Application class, register that class in AndroidManifest.xml, then run the app and open chrome://inspect on your laptop and click Inspect.
Do I need any extra libraries for network inspection?Only the core stetho dependency is required; for network inspection you additionally need one of the network helper artifacts, such as stetho-okhttp3 for OkHttp 3.x (or stetho-okhttp for 2.x), or use StethoURLConnectionManager with HttpURLConnection.
Any gotchas when integrating network inspection?With HttpURLConnection you must explicitly add an Accept-Encoding: gzip header and manually handle compressed responses for Stetho to report payload sizes correctly, and interceptor order matters when using OkHttp.
Who is this for and is it still maintained?It's for Android developers who want browser-based debugging of their app; the repository is archived, so it is no longer actively maintained.
Can I extend the dumpapp CLI with my own commands?Yes, custom dumpapp plugins can be added easily during Stetho's configuration step to extend the command-line interface with your own functionality.
Can I customize the JavaScript console it provides?Yes, Stetho supports enabling an optional JavaScript console, and you can customize the JS runtime further via the stetho-js-rhino module.
Does it support older OkHttp versions?Yes, both OkHttp 2.x and 3.x are supported for automatic network inspection, though 2.x requires the separate stetho-okhttp artifact and slightly different syntax than stetho-okhttp3.
Creator
facebook
Size
2.3 MB
Stars
12.6K
Age
11y
Commits · 90 Days