Remote debugging/inspecting android application at runtime using Chrome developer tool and Facebook Stetho.

We all know how to view the source code of any web page or inspect element and other stuff on any browser. This can be done using any browser even Internet Explorer 4 can do that. But what’s new. Just like Android Studio, Chrome is my personal favorite even though both of them combined eats up system ram heavily. Chrome is a powerful tool because of a lot of powerful Chrome apps and developer tools are available and supported.

In this blog, we are going to find out some of the cool features of using Chrome in respect to Android application debugging/inspecting.

One such feature is remote debugging Android devices via chrome developer tools.

Remote Debugging

If you knows web developement,  I am sure your website contains mobile friendly web pages. But there are times when loading your site on mobile doesn’t look or behave as expected. Thus you need a developer tool for mobile as well just like chrome developer tool for website or firebug if in case you are an FireFox lover.

We can do the same for web pages loading on Android devices using Chrome application.

Remote Debugging benefits

  1. Testing on real device thus you can tweak the problem and fix it when your site is running on mobiles.
  2. Screencasting the entire page or chrome application using System remotely on your developement machine.

Requirement to enable Remote Debugging

There are some requirements to perform remote debugging smoothly viz,

How to start debugging via Android device

  1. On your Android device, select Settings > Developer Options > Enable USB Debugging.
  2. On your development machine, open Chrome. You should be signed in to Chrome with one of your Google accounts. Remote debugging does not work in Incognito Mode or Guest Mode.
  3. Open DevTools.
  4. In DevTools, click the Main Menu , then select More tools > Remote devices
  5. In DevTools, click the Settings tab, if another tab is showing.
  6. Make sure that Discover USB devices option is enabled.
  7. Connect your Android device directly to your development machine using a USB cable. Don’t use any intermediate USB hubs. If this is your first time connecting your Android device to this development machine, your device shows up under Unknown, with the text Pending Authorization below it.
  8. If your device is showing up as Unknown, accept the Allow USB Debugging permission prompt on your Android device. Unknown is replaced with the model name of your Android device. The green circle and the Connected text indicate that you are all set to remotely debug your Android device from your development machine.
  9. If you don’t already have Chrome open on your Android device, open it now.
  10. Back in DevTools, click the tab that matches your device’s model name. At the top of this page, you see your Android device’s model name, followed by its serial number. Below that, you can see the version of Chrome that’s running on the device, with the version number in parentheses. Each open Chrome tab gets its own section. You can interact with that tab from this section. If there are any apps using WebView, you see a section for each of those apps, too. The screenshot below does not have any tabs or WebViews open. 

 

For further reading: Click here

Facebook Stetho

Chrome Developer Tools only enable debugging for chrome app and web views. For debugging your Android application we can use debug bridge like stetho which provide access to the Chrome Developer Tools feature for your application.

Set-up

Add Stetho dependency in module level gradle

In case you are using okhttp3 network library then to log request and response we can use the following dependency:

For other, Check here

Update application class to initialize stetho with defaults:

Enable network inspection:

On Adding stetho interceptor in your application’s okhttp client you can modify request/response and monitor it accurately. Now we are ready to inspect and debug Application.

Once done with the set-up instructions,  just start your app and point your development machine browser to chrome://inspect. Click the “Inspect” button to begin.


 

 

 

 

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close