Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stetho: Don't see Network calls in console

Everything with Stetho works great in my sample app I tested after going through this YouTube tutorial (SQLite, SharedPreferences show) except for seeing the Network Calls which I'd love to get working.

I'm making numerous API calls when the app is loaded. One for example is within my Service.java Class as seen in the link below. Perhaps it's not showing up in Stetho because the API call happens when the app is loaded before Stetho can be opened. Any ideas would be appreciated to get this feature working.

I initialize Stetho in my MainActivity.java. In onCreate() I have

    // Initialize Stetho
    Stetho.initialize(
            Stetho.newInitializerBuilder(this)
                    .enableDumpapp(new SampleDumperPluginsProvider(this))
                    .enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this))
                    .build());

Then I also included a Stetho Class at the bottom.

// Create class for Stetho
private static class SampleDumperPluginsProvider implements DumperPluginsProvider {
    private final Context mContext;

    public SampleDumperPluginsProvider(Context context){mContext = context;}

    @Override
    public Iterable<DumperPlugin> get() {
        ArrayList<DumperPlugin> plugins = new ArrayList<>();
        for (DumperPlugin defaultPlugin : Stetho.defaultDumperPluginsProvider(mContext).get()) {
            plugins.add(defaultPlugin);
        }
        //plugins.add(new SyncAdapterFragment());
        return plugins;
    }
}

and of course I also have the proper dependencies

compile 'com.facebook.stetho:stetho:1.3.0'

Thanks!

like image 863
Adam Hurwitz Avatar asked Feb 16 '16 22:02

Adam Hurwitz


1 Answers

I had the same issue with missing early network calls, but there's an easy way to see all the calls using a simple breakpoint, since you can connect to a 'paused' application:

  • just run your application in debug and put a breakpoint before your very first network call (i.e. somewhere in the onCreate of your application for example, but after Stetho is initialised of course :-)
  • open Chrome (chrome://inspect/#devices), and you should see your Android application (which is waiting on a breakpoint at this moment)
  • just click 'inspect', and the dev tools will open.
  • select the network tab if it isn't selected
  • click the 'resume' button in the debug window (not the 'run' button!)

-> you should see all your (network) calls now (if Stetho is correctly integrated of course)

  • I tried this only on my device, not sure if the emulator behaves the same

  • your Stetho init is correct, I used the same construct.

  • to see network calls, you need to add a 'StethoInterceptor()' into your http client. I'm just starting with Android, so I cannot immediately tell you how to do this in your code, but here's how I inserted Stetho (1.3.1) in Retrofit 2 (2.0.0-beta4)

    // add a Facebook StethoInterceptor to the OkHttpClient's list of network interceptors
    OkHttpClient okClient = new OkHttpClient.Builder()
            .addNetworkInterceptor(new StethoInterceptor())
            .build();
    
    mRetrofit = new Retrofit.Builder()
            .client(okClient)
            .baseUrl(BASE_URL)
            .build();
    
like image 111
Ronny Webers Avatar answered Sep 20 '22 16:09

Ronny Webers