![]() |
VOOZH | about |
Stetho is an open-source debug library developed by Facebook. It allows you to use chrome debugging tools to troubleshoot network traffic., thus it provides a rich, interactive debugging experience for android developers. Stetho easily and smoothly debug network calls. It is a Sophisticated Debug Bridge for Android Applications. When enabled, developers have a path to the Chrome Developer Tools feature natively part of the Chrome desktop browser. Developers can also prefer to allow the optional dumpApp tool which allows a powerful command-line interface to application internals. Without limiting its functionality to just network inspection, JavaScript console, database inspection, etc. We are going to implement this project using both Java and Kotlin Programming Language for Android.
The problem with debugging network traffic while developing android applications, debugger facing problems with traditional debugging tools get messed up and inspection got very complex while switching the devices.
The debugging is more reliable and easy with the Stetho library because it uses the chrome debugging tool which supports web-socket and uses it for network debugging. Stetho automated the call inspection, so it becomes more important for android developers.
Stetho uses an HTTP web Socket server that sends all debugging information to the browser. It is accessible through:
chrome://inspect
Go to Module build.gradle file and add this dependency and click on Sync Now button.
implementation 'com.facebook.stetho:stetho-okhttp3:1.5.1'
The following method is the easiest and simpler way to enable network inspection when you constructing the okHttpClient instance:
okHttpClient.Builder().addNetworkInterceptor(StethoInterceptor()).build()
Run the emulator on the device. Then open chrome://inspect on Chrome and your emulator device should appear, after that click inspects to launch a new window, and click the network tab to watch network traffics.