-
Notifications
You must be signed in to change notification settings - Fork 0
Debugging with Stetho
Facebook's Stetho project enables you to use Chrome debugging tools to troubleshoot network traffic, database files, and view layouts. With this library, you need to have an active emulator or device running, and you use will Chrome to connect to the device by typing chrome://inspect
.
For network traffic, you can use the Network Inspector:
Any SQLite database can also be inspected using the Resources
-> Web SQL
tab:
The third-party Android Async Http Client library uses the Apache HTTP Client, which is not currently supported by Stetho as noted in this issue. Troubleshooting networking issues works best with OkHttp or Retrofit. Regardless, you can still use this library for SQLite database inspection.
Setup your app/build.gradle
file:
// Gradle dependency on Stetho
dependencies {
compile 'com.facebook.stetho:stetho:1.4.1'
}
Next, initialize Stetho inside your Application object:
public class MyApplication extends Application {
public void onCreate() {
super.onCreate();
Stetho.initializeWithDefaults(this);
}
}
If you are also using Stetho with the OkHttp or Retrofit, make sure to include the OkHttp library as well:
dependencies {
// add below Stetho main dependency
compile 'com.facebook.stetho:stetho-okhttp3:1.4.1' // for OkHttp library
}
You will also need to add the StethoInterceptor
when constructing the OkHttpClient
instance:
OkHttpClient client = new OkHttpClient.Builder()
.addNetworkInterceptor(new StethoInterceptor())
.build();
Start your emulator or device. Then visit chrome://inspect
on your Chrome desktop and your emulator device should appear. Click on Inspect
to launch a new window.
Click on the Network
tab. Now you can start watching network traffic between your emulator or device in real-time!
Created by CodePath with much help from the community. Contributed content licensed under cc-wiki with attribution required. You are free to remix and reuse, as long as you attribute and use a similar license.
Finding these guides helpful?
We need help from the broader community to improve these guides, add new topics and keep the topics up-to-date. See our contribution guidelines here and our topic issues list for great ways to help out.
Check these same guides through our standalone viewer for a better browsing experience and an improved search. Follow us on twitter @codepath for access to more useful Android development resources.
Interested in ramping up on Android quickly?
(US Only) If you are an existing engineer with 2+ years of professional experience in software development and are serious about ramping up on Android quickly, be sure to apply for our free evening 8-week Android bootcamp.
We've trained over a thousand engineers from top companies including Apple, Twitter, Airbnb, Uber, and many others leveraging this program. The course is taught by Android experts from the industry and is specifically designed for existing engineers.
Not in the United States? Please fill out our application of interest form and we’ll notify you as classes become available in your area powered by local organizers.