Android:Adding the Android debug tools

debug tools,Improving the exceptional of services and products is an incredibly essential topic for software program development industry. The improvement system consists of a whole lot of components that want to be labored out continuously. In this newsletter we can communicate immediately about application code debugging as my vicinity of knowledge. Debugging is one of the maximum important part of the software program developement manner. To offer the outstanding product to users we should discover and attach bugs fast and timely.

In Techery, we try no longer most effective to satisfy but also exceed the expectancies of our customers and technical companions. We have used many one of a kind debug gear and every one has its personal advantages. It is not convenient to have lots of dependencies in a assignment and switch all of the time among distinct equipment to inspect network or database layers. A long time we have looked for the answer which meets all our wishes till someday got here up has an idea to create our own.

I would love to percentage the enjoy of utilization exceptional debugging equipment and decided to create a sequence of articles on this subject matter:

  • Android debug tools — Android apps debugging tools overview
  • SQLite debug tools — overview of tools for Android SQLite database debugging
  • Android log debug tools — an overview of tools for logs tracking
  • HTTP debug tools — overview of tools for Android HTTP debugging

We would like to make evaluate and proportion our enjoy of usage of different debug gear and hope this article will assist you to determine which one you shoud use.

Android Profiler — profiler of Android Studio Facebook Stetho — debug bridge for Android apps

DebugDrawer — drawer for faster development AppSpector — debug tool for Android and iOS

debug tools,Android Studio Profiler

debug tools,The Android Profiler tool provides actual-time information to help you profile community layer and understand how your app uses CPU, reminiscence, and battery sources. Since Android Studio three.Zero version you enable advanced profiling that works when your app is launched at the devices with Android 7.1 and higher.

debug tools,Features

debug tools,The profiler window shows the CPU, memory, network, and battery usage and looks the following way:

Network inspection

If you click on the network timeline the profile shows you the detailed info about requests.

The window above contains the Connection View tab that shows a list of requests with size, time, status, request, response, and time.

debug tools,Memory inspection

debug tools,The Memory profiler shows graph with RAM usage and looks the following way:

Using this feature you can find functions that create extra objects and decrease amount of garbage collection events.

debug tools,Advanced profiling

debug tools,You can edit the Run configurations of your app to enable the Advanced profiling option as on the following screenshot:

Features provided by advanced profiling:

  • All profiler windows support the event timeline
  • Memory Profiler shows the number of allocated objects
  • Memory Profiler shows the garbage collection events
  • Network Profiler shows details about all transmitted files

Pros and cons

Android Studio profiler works out of the container and also you don’t need to integrate 1/3-birthday celebration dependencies into your venture. The to be had monitors(Network, CPU, Memory, and Energy) display actually exhaustive information about your app. I without a doubt like this implementation of the Network display due to the fact you may choose a time frame on the timeline and punctiliously inspect requests.

There isn’t any profiler for database and it is the biggest drawback, in my view, what makes us to use other tools, for instance the SQLStout plugin so that it will be overviewed in our next article about SQLite debug equipment.

Facebook Stetho

Stetho is a debug bridge for Android that allows you to access to the Chrome Developer Tools to inspect your app.

Integration

download the middle Stetho library in your task upload the subsequent line to the dependencies block:

implementation 'com.facebook.stetho:stetho:1.5.0'
implementation 'com.facebook.stetho:stetho-okhttp3:1.5.0'

initialize Stetho you must be adding the subsequent line to the onCreate method of the Application elegance of your app:

Stetho.initializeWithDefaults(this);

To make Stetho able to show network data with the OkHttp client you should add an interceptor like this:

new OkHttpClient.Builder()
    .addNetworkInterceptor(new StethoInterceptor())
    .build()

Features

Stetho allows you to inspect a network and storage layers of your app.

You can switch between inspectors using tabs.

Network inspection

The Network tab shows a table with requests and looks as follows:

The table shows a status, type, time, size, and method of each request. You click on a row to see detailed info:

Database inspection

The Resource tab shows SQLite table of your app and looks the following way:

This window is a simple desk without search and paging. It may contain bugs, for instance, at the screenshot above you may see identification columns.

Pros and cons

Stetho is a loose device that permits you to check out network and garage layers. You can also deploy the Stetho-Realm library of you need to look at Realm database. Stetho is unfastened and it is simple to get began however it contains insects, unpleasant person interface and poor functionality.

debug tools,DebugDrawer

debug tools,There are many libraries that allow you to integrate a configurable navigation drawer in your app. All of them have similar functionality.

debug tools,Integration

debug tools,To download DebugDrawer you have to add the subsequent line to the dependencies block of the build.Gradle file:

debugImplementation ‘io.palaima.debugdrawer:debugdrawer:0.8.0’

You can configure the debug navigation drawer functionality through adding specific modules for your challenge. For example, if you want to look at the community layer of your app you can upload the subsequent line:

implementation 'io.palaima.debugdrawer:debugdrawer-okhttp3:0.8.0'

To initialize DebugView you should add the subsequent strains to the onCreate method of your Activity .

SwitchAction switchAction = new SwitchAction("Test switch", new SwitchAction.Listener() {
 @Override
 public void onCheckedChanged(boolean value) {
  Toast.makeText(MainActivity.this, "Switch checked", Toast.LENGTH_LONG).show();
 }
});

ButtonAction buttonAction = new ButtonAction("Test button", new ButtonAction.Listener() {
 @Override
 public void onClick() {
  Toast.makeText(MainActivity.this, "Button clicked", Toast.LENGTH_LONG).show();
 }
});

SpinnerAction < String > spinnerAction = new SpinnerAction < > (
 Arrays.asList("First", "Second", "Third"),
 new SpinnerAction.OnItemSelectedListener < String > () {
  @Override public void onItemSelected(String value) {
   Toast.makeText(MainActivity.this, "Spinner item selected - " + value, Toast.LENGTH_LONG).show();
  }
 }
);

debugDrawer = new DebugDrawer.Builder(this)
 .modules(
  new ActionsModule(switchAction, buttonAction, spinnerAction),
  new FpsModule(Takt.stock(getApplication())),
  new LocationModule(this),
  new ScalpelModule(this),
  new TimberModule(),
  new OkHttp3Module(okHttpClient),
  new PicassoModule(picasso),
  new GlideModule(Glide.get(getContext())),
  new DeviceModule(this),
  new BuildModule(this),
  new NetworkModule(this),
  new SettingsModule(this)
 ).build();

debug tools,Features

debug tools,The navigation debug drawer depends on your configuration may look the following way:

DebugDrawer allows you quickly check info about your device, change settings or mock location.

Network inspection

DebugView uses the Chuck library under the hood and allows you to inspect network requests.

The Chuck library shows a list with all requests and allows you to check details.

Pros and cons

DebugDrawer offers you brief get right of entry to to the tool data and settings, allows you to mock place and network connection nation. This can simplify a procedure of testing but it is hard to investigate community request on the display screen of a cell device. There is likewise no capability for database layer inspection.

debug tools,AppSpector

debug tools,AppSpector is a provider for debugging iOS and Android apps that allows you to look at and control your apps remotely in real-time using a simple interface. The full documentation available here.

debug tools,Integration

debug tools,To get started with AppSpector you have to go through a easy registration shape and create your task or upload an enterprise.

To combine AppSpector into your app you must regulate the construct.Gradle document inside the following way:

buildscript {
    repositories {
        jcenter()
        google()
        maven {
            url "https://maven.appspector.com/artifactory/android-sdk"
        }
    }

    dependencies {
        classpath "com.appspector:android-sdk-plugin:1.+"
    }
}

apply plugin: 'com.android.application'
// Put AppSpector plugin after Android plugin
apply plugin: 'com.appspector.sdk'

repositories {
    maven {
        url "https://maven.appspector.com/artifactory/android-sdk"
    }
}

dependencies {
    implementation "com.appspector:android-sdk:1.+"
}

And initialize AppSpector within the onCreate method inside the Application magnificence of your app:

AppSpector
        .build(this)
        .withDefaultMonitors()           .run("android_OGMyYzA3NGYtNDkxNy00ZWRiLTgxOTktNjQ5YjIzMTZjOWM4");

Features

When you run your app a new session will be created and you will see it in the main AppSpector window in browser.

When you click in a certain session you can inspect your app using different monitors.

Performance inspection

The Performance window shows graphs with different metrics such as CPU, Memory, Network, Disk, FPS, and Battery usage.

This monitor helps to detect resource leaks, usage of disk, and FPS.

Network inspection

The Network monitor shows a table with requests so you can click on a certain row to see details info such as request and response.

This window also contains the search, filter, and export functions.

It is really convenient to use them if you have a large app.

Database inspection

The SQLite monitor allows you to inspect a database and invoke SQL requests.

It is easy to search a certain record because this monitor contains handful paging.

Pros and cons

AppSpector has best consumer interface. It is straightforward to navigate via it and find wished monitor. You can proportion your consultation together with your teammates simply by using coping url deal with from a browser and sending it. The shared consultation is available for all contributors on your organization. AppSpector incorporates many exclusive video display units with handful search and filter options. The trial length is 14 days. AppSpector also supports two platforms: iOS and Android. You test the stay demo here.

Conclusions

Now, we’re approximately to quit this journey through debugging equipment for Android. We shared our enjoy of different profilers usage and explained why we decided to create our very own. In the next articles we are able to cross deeply and make review of tools for a particular layer of app which includes community and database. Join to our Slack channel. Thanks for studying and live tuned!