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.
WebKit Inspector is the internal name of the Chrome Developer Tools feature.
It 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 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.
SQLite databases can be visualized and interactively explored with full read/write capabilities.
Dumpapp extends beyond the Inspector 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!
Assemble the JAR files locally using:
./gradlew assemble
Copy the relevant jar files to your libs/
directory. Only the main stetho
jar file is strictly required, however you may wish to copy
stetho-urlconnection
or stetho-okhttp
for simplified network integration.
Also take note that you will need to rename the jar files to avoid conflicts.
The jar files are located in their respective build
directories:
./stetho/build/intermediates/bundles/debug/classes.jar
./stetho-urlconnection/build/intermediates/bundles/debug/classes.jar
./stetho-okhttp/build/intermediates/bundles/debug/classes.jar
You will also need Apache's commons-cli
library, which you can access from
build.gradle
:
compile 'commons-cli:commons-cli:1.2'
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.initialize(
Stetho.newInitializerBuilder(this)
.enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
.enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this))
.build());
}
}
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.
If you are using the popular OkHttp library at the 2.2.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:
OkHttpClient client = new OkHttpClient();
client.networkInterceptors().add(new StethoInterceptor());
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 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 MyDumperPluginsProvider(context))
.build())
private static class MyDumperPluginsProvider implements DumperPluginsProvider {
...
public Iterable<DumperPlugin> get() {
ArrayList<DumperPlugin> plugins = new ArrayList<DumperPlugin>();
for (DumperPlugin defaultPlugin : Stetho.defaultDumperPluginsProvider(mContext).get()) {
plugins.add(defaultPlugin);
}
plugins.add(new MyDumperPlugin());
return plugins;
}
}
See the stetho-sample
project for more details.
See the CONTRIBUTING.md file for how to help out.
Stetho is BSD-licensed. We also provide an additional patent grant.