← Back to facebook/stetho

How to Deploy & Use facebook/stetho

Stetho Deployment and Usage Guide

Prerequisites

  • Android Development Environment: Android Studio or equivalent IDE with Android SDK
  • Android Device or Emulator: Running Android 4.1 (API level 16) or higher
  • Chrome Browser: Latest version for Chrome Developer Tools integration
  • Gradle: For dependency management and building

Installation

Adding Stetho to Your Project

  1. Include the Stetho dependency in your build.gradle file:
implementation 'com.facebook.stetho:stetho:1.6.0'
  1. Optional network inspection dependencies (choose based on your networking library):
// For OkHttp 3.x
implementation 'com.facebook.stetho:stetho-okhttp3:1.6.0'

// For OkHttp 2.x
implementation 'com.facebook.stetho:stetho-okhttp:1.6.0'

// For HttpURLConnection
implementation 'com.facebook.stetho:stetho-urlconnection:1.6.0'

// For JavaScript console
implementation 'com.facebook.stetho:stetho-js-rhino:1.6.0'
  1. Sync your project with Gradle files.

Configuration

Basic Initialization

Add Stetho initialization to your Application class:

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

Register Application Class

Ensure your Application class is registered in AndroidManifest.xml:

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

Network Inspection Setup

For OkHttp 3.x:

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

For HttpURLConnection:

HttpURLConnection connection = (HttpURLConnection) url.openConnection();
StethoURLConnectionManager stethoManager = new StethoURLConnectionManager("MyNetwork");
stethoManager.preConnect(connection, requestMethod, requestHeaders);
// ... perform request
stethoManager.postConnect();

Build & Run

Local Development

  1. Build your Android project as usual (Run/Debug configuration in Android Studio)
  2. Enable USB debugging on your Android device or start an emulator
  3. Connect your device to your development machine
  4. Start your app on the device/emulator

Accessing Chrome Developer Tools

  1. Open Chrome browser on your development machine
  2. Navigate to chrome://inspect
  3. Find your connected device and app in the "Devices" section
  4. Click the "Inspect" button next to your app
  5. Chrome Developer Tools will open, allowing you to inspect:
    • Network requests
    • Database content
    • Shared preferences
    • View hierarchy
    • JavaScript console (if enabled)

Deployment

Stetho is a development and debugging tool and should NOT be included in production builds. Here's how to handle it:

Development Builds

Keep Stetho enabled in debug builds only:

debugImplementation 'com.facebook.stetho:stetho:1.6.0'

Production Builds

Exclude Stetho from release builds:

releaseImplementation 'com.facebook.stetho:stetho-no-op:1.6.0'

Or simply don't include it in release configurations.

Deployment Platforms

Since Stetho is an Android library, deployment follows standard Android app deployment practices:

  • Google Play Store: Standard Android app deployment
  • Internal Distribution: Use Android App Bundles or APK for internal testing
  • Enterprise: Deploy through enterprise app stores or direct APK distribution

Troubleshooting

Common Issues and Solutions

1. "Inspect" Button Not Visible in chrome://inspect

Solution: Ensure your Application class is properly registered in AndroidManifest.xml and that Stetho is initialized in onCreate().

2. Network Inspection Not Working

Solution: Verify you're using the correct Stetho interceptor for your OkHttp version:

  • Use stetho-okhttp3 for OkHttp 3.x
  • Use stetho-okhttp for OkHttp 2.x

3. Database Inspection Shows No Tables

Solution: Ensure your database is created and accessible. Stetho can only inspect databases that your app has permission to access.

4. Chrome Developer Tools Fails to Connect

Solution:

  • Check that USB debugging is enabled on the device
  • Verify the device is properly connected (visible in adb devices)
  • Ensure the app is running and Stetho is initialized

5. Performance Issues in Debug Mode

Solution: Stetho adds overhead. Use it only during development and remove/disable it for performance testing and production builds.

6. JavaScript Console Not Available

Solution: Add the stetho-js-rhino dependency and ensure you've initialized Stetho with the JavaScript runtime enabled.

Advanced Troubleshooting

For custom dumpapp plugins or advanced configuration issues, refer to the sample project in the stetho-sample directory for implementation examples.