Stetho: do not see network calls in the console

Everything with Stetho works great in my sample application, which I tested after going through this YouTube tutorial (SQLite, SharedPreferences show), except for viewing the Network of Calls that I would like to receive.

I make numerous API calls when loading the application. For example, in my Service.java class, as shown in the link below. It may not appear in Stetho because an API call occurs when the application loads before Stetho can be opened. Any ideas would be appreciated to make this feature work.

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 the Stetho Class below.

 // 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 corresponding dependencies

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

Thanks!

+5
source share
1 answer

I had the same problem with the lack of early network calls, but there was an easy way to see all the calls using a simple breakpoint, as you can connect to the "suspended" application:

  • just run the application in debugging and put a breakpoint in front of the very first network call (for example, somewhere in the onCreate of your application, for example, after Stetho is initialized, of course :-)
  • open Chrome (chrome: // inspect / # devices) and you will see your Android app (which is currently waiting for a breakpoint)
  • just hit check and the dev tools will open.
  • select the network tab if it is not selected
  • click the "resume" button in the debug window (and not the "start" button!)

-> you should see all your (network) calls (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 "StethoInterceptor ()" to your http client. I'm just starting out with Android, so I can’t tell you right away how to do this in code, but here is how I inserted Stetho (1.3.1) into Retrofit 2 (2.0.0-beta4)

     // add a Facebook StethoInterceptor to the OkHttpClient list of network interceptors OkHttpClient okClient = new OkHttpClient.Builder() .addNetworkInterceptor(new StethoInterceptor()) .build(); mRetrofit = new Retrofit.Builder() .client(okClient) .baseUrl(BASE_URL) .build(); 
+8
source

Source: https://habr.com/ru/post/1243181/


All Articles