Stetho Debugging Tool For Android

Posted By : Prince Bhardwaj | 31-May-2018

Stetho is an open source debugging stage, created by Facebook, that offers a rich and very intelligent troubleshooting background to Android designers. With Stetho, investigating local Android applications moves toward becoming as basic as troubleshooting a site page, since it enables you to utilize Google Chrome's designer apparatuses to perform different troubleshooting exercises, for example, see chain of importance examination, organize assessment, SQLite database administration, and that's only the tip of the iceberg. 

In this instructional exercise, you will figure out how to add Stetho to an Android venture and utilize both Google Chrome's designer devices and Stetho's order line utility, dumpapp, to troubleshoot it.

 

Adding Gradle Dependencies :

 

To incorporate the Stetho library in your undertaking, you have to include com.facebook.stetho:stetho as an accumulate reliance in the application module's build. gradle record as:

java compile 'com.facebook.stetho:stetho:1.1.1'

 

In this exercise, you will utilize OkHttp, a prominent networking library from Square, to deal with all system connections, since it plays extremely well with Stetho. Include it as another compile dependency:

java compile 'com.facebook.stetho:stetho-okhttp:1.1.1'

 

Initializing Stetho :

 

Stage 1: Creating a Custom Application Class 

The best time to initialize Stetho is the point at which your application is beginning. In this manner, you need to make another class that extends Application and instates Stetho inside its onCreate technique. 

Make another class called MyApplication and override its onCreate strategy:


java public class MyApplication extends Application {

@Override
public void onCreate() {
    super.onCreate();
} }

 

An instance is needed to initialize Stetho.InitializerBuilder, via Stetho.newInitializerBuilder . If you moreover need to engage dumpapp, you should call enableDumpapp. At the point when Stetho.InitializerBuilder is readied, you can call its amass procedure to deliver an Initializer question and pass it to the Stetho. initialize system.

For present, how about if we empower the default usefulness by utilizing the default InspectorModulesProvider and DumperPluginsProvider. In onCreate, add Accompanying code -

```java/Create an InitializerBuilder Stetho.InitializerBuilder initializerBuilder = Stetho.newInitializerBuilder(this); 

/Enable Chrome DevTools initializerBuilder.enableWebKitInspector( Stetho.defaultInspectorModulesProvider(this) ); 

/Enable summon line interface initializerBuilder.enableDumpapp( Stetho.defaultDumperPluginsProvider(context) ); 

/Use InitializerBuilder instead of Initializer Stetho.Initializer initializer = initializerBuilder.build();

/Initialize Stetho with the Initializer Stetho.initialize(initializer);

 

Stage 2: Editing the Manifest 

To let the Android working framework realize that you have a custom Application class, add an attribute called android: name to the manifest's application tag and set the value to the name of your custom Application class.

 

Using Chrome's Dev Tools

 

Subsequent to incorporating and introducing your application on an Android gadget (or the emulator), begin Google Chrome and sort in chrome://inspect in the address bar. Now, you need to click on the inspect link to open the Developer's tools. Now, you can see all the network calls and their responses that your application hits.

About Author

Author Image
Prince Bhardwaj

Prince Bhardwaj is having Talent as Application Developer, he is an enthusiastic team player in Oodles Technologies.

Request for Proposal

Name is required

Comment is required

Sending message..