paint-brush
Debugging Tips Capsule For Beginnersby@induction
306 reads
306 reads

Debugging Tips Capsule For Beginners

by Vision NPJanuary 9th, 2023
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Some apps can be buggy or nonworking on the Android OS. Repeated error messages like “App is not responding” can create problems. When the app crashes, the OS keeps the record in the logs that can be used to inspect the information about the app crash events. This article will show you how to debug the Android app using the logs.
featured image - Debugging Tips Capsule For Beginners
Vision NP HackerNoon profile picture

Android OS is an open and innovative platform to allow developers to be free and creative. There are many apps to run on the Android OS, but some apps can be buggy or nonworking. Repeated cashing, stopping, and exhibiting repeated error messages like “App is not responding” can create problems. When the app crashes, the OS keeps the record in the logs that can be used to inspect the information about the app crash events, factors causing the app to crash, etc. This article will show you how to debug the Android app using the logs.

Prerequisites:

Before starting, you should have the following things with you.

  1. Android Studio (Latest version contains ADB). You can download it from the official site.
  2. An Android device or an emulator.

Now carefully follow the following steps:

STEP-1: Enable USB Debugging:

You need to enable it from the Android device you will connect to the PC.


  1. Enable “Developer options.” You check my previous article to understand the steps.
  2. Go to “Settings” and tap “System.
  3. Select “Advanced.”
  4. Tap “Developer options.”
  5. Find an option, “USB debugging.”
  6. Toggle right to enable.

STEP-2: Connect the Android device and install the target app:

This method includes the Android Debug Bridge (ADB). Please note that your Android Studio should have an adb.exe file on your PC.

You can check C:\Users\Username\AppData\Local\Android\Sdk\platform-tools, and if adb.exe is there, you are okay; otherwise, check here to learn the ADB installation process. Follow the steps below:

  1. Once you connect to the Android device, you will see a message, “Allow USB Debugging?” tap “Allow.”
  2. Select the exact device on Android Studio, as shown below.
  3. You can run the app by clicking on the green play option.
  4. You can reproduce the crash by using the target app UI to inspect the exact events of crashes in the logs.
  5. Now click on the Logcat option for more information after the crash, or use the log filter option labelling “Error” for the desired errors.


P.S. Google has enabled it to run ADB and Fastboot without installing Android Studio.

In this case, you can prefer the following options.

  1. Connect your Android device to your PC.
  2. Allow USB Debugging on your device (Skip it if you using an emulator).

Image source


  1. You can open the portable folder version for the targeted software for ADB.
  2. Hit SHIFT+Right Click on the blank space of the Folder to open Command Prompt.
  3. You can use adb logcat -c command to delete the history there.
  4. You can create a new desktop folder on the desktop. Now press the SHIFT key+Right Click on the folder.
  5. Go to the “context menu” and click “Copy as Path.
  6. Now, use the command adb logcat -v time > to paste the path in the log window. And then you can see it as adb logcat -v time > “D:\Logs” there.
  7. You can adjust the name for the path.
  8. Reproduce the crashes using the app UI.


If you have Android 11 or higher, you can debug wirelessly without connecting a physical device to the PC.

In this case, you can follow the following steps:

Open Android Studio and click on the “Pair Devices Using Wi-Fi” option from the run configurations menu, as shown below.

  1. A pop-up window says, Pair devices over Wi-Fi with QR code.
  2. Enable “Wireless debugging” on your Android device.
  3. Tap on the “Pair device with QR code” option.
  4. Now note down the six-digit code and tap “Pair.”
  5. Now, you can use the “Wireless debugging” feature on ADB.

STEP-3: Inspect the errors:

All the above steps configure all the necessary components for debugging the Android apps via USB connection or wirelessly. You need to have the basic knowledge to read the logs. Here you can capture the bug reports by using ADB as follows:

1. If you have connected only one device to the PC, enter the following command.

$ adb bugreport E:\Reports\MyBugReports

2. You need to specify the path. Otherwise, it will be saved to the local directory of your PC. By default, bug reports are in the /bugreports and you can enter the following command to view them.

$ adb shell ls /bugreports/
bugreport-foo-bar.xxx.YYYY-MM-DD-HH-MM-SS-dumpstate_log-yyy.txt
bugreport-foo-bar.xxx.YYYY-MM-DD-HH-MM-SS.zip
Dumpstate-stats.txt
  1. pull the zip file via adb pull: using the following command:
$ adb pull /bugreports/bugreport-foo-bar.xxx.YYYY-MM-DD-HH-MM-SS.zip
  1. Analyze the bug report in ZIP format, as shown in the following figure.


The ZIP file contains bugreport-BUILD_ID-DATE.txt file, which is the most important to inspect the error. In addition, the bug reports consist of the following:

  1. Diagnostic output for system services (dumpsys),
  2. Error logs (dumpstate), and
  3. System message logs (logcat).


You can also capture the system trace using the Systrace tool, and the dumpstate tool copies the file to store in the FS folder, which can be very useful for debugging the app.


Here are a few myths about app testing that you should not believe.

1. Google already verifies mobile apps: This is the most notable myth because Google provides the essential frameworks and tools for developing safe apps, so they do not deeply check the apps’ codes or bugs before making them online on PlayStore. So, developers should be responsible for any security breaches or persistent bugs in their apps.

2. Testing an app on a few devices is enough: Some developers believe their apps run all devices after testing on a limited number of devices, but there are wide ranges of devices having their own hardware or software configurations so that the apps may exhibit some bugs. So the app testing should be performed on a large scale before propagating them on the internet.

3. Emulators are the perfect options for testing the apps: It is another myth. A good emulator allows developers or app testers to test apps for the initial stage of the app’s development, which means testing apps on emulators may not guarantee the apps’ performance on real-world devices.


For more detailed information about reading the bug reports from the logs, you can keep learning from this great resource. Learning new things will never be too late, so get started today.


Conclusion:

The codes written for the android apps should execute correctly for smooth functioning. Sometimes, the apps may exhibit bugs that need to be fixed using the proper debugging tools. Nowadays, many platforms claim that they debug the app remotely, but some can be malicious to steal sensitive data, so you have to be very careful.

Enabling the USB Debugging option all the time can be risky if you connect your device to a public USB charging station or some infected PC. Try to adopt all the safety measures first.

If you’re a newcomer to learning mobile debugging, you can find great online resources to boost your skill. Perfectly working apps are desirable for most businesses. Hence, they try to release bug-free apps to the users, and they often run bounties or cash prizes for detecting the bugs in their apps, so if you learn the debugging techniques from the beginning, your career is bright in this field.


Good Luck!