Facebook has open sourced Stetho, an Android debugging bridge enabling developers to debug their apps using Chrome DevTools.
Until now developers could remotely debug a limited type of Android applications with Chrome, namely browser tabs and WebViews. With Stetho, they can remotely debug in Chrome all Android applications.
To use Stetho, developers need to instrument their Android app by hooking up the Application class with the Stetho initializer which starts a WebSocket HTTP server, as shown in the following snippet:
Stetho.initialize(Stetho.newInitializerBuilder(context)
.enableDumpapp(Stetho.defaultDumperPluginsProvider(context))
.enableWebKitInspector(Stetho.defaultInspectorModulesProvider(context))
.build());
Then they can select their device from the DevTools Devices page (chrome://inspect/#devices
) and use the debugging tools available in Chrome including network and database inspection. In addition, Stetho has a command-line scripting tool called dumpapp
and a way to instrument any custom component to address the shortcomings of the dumpsys
tool.
According to source code comments, Stetho implements a “limited version of the Chrome Debugger WebSocket protocol (using JSON-RPC 2.0)” to communicate with Chrome.
We asked Josh Guilfoyle, a Facebook developer working on Stetho, what are some of the features to be expected in the future:
The main feature in the pipeline right now is UI inspection which allows developers to both view and edit Android UI hierarchies from the DevTools interface. We're also working on a lot of smaller features like working with SharedPreferences data, displaying files, and even timeline tracing.
We're also excited to begin rolling out a more powerful set of command line dumper plugins including a network stats aggregator, background task CPU usage attribution, and a way to dump the Java heap of a running program.
Stetho comes with a BSD license and a patent grant.