There can be several reasons why bugs can creep into your apps. A robust system must detect them and make suitable changes to the Play Store app to ensure it works properly. The Android Studio gives an advanced debugging feature. It permits developers to undertake the following activities:
- Create the breakpoints in Kotlin, Java, and C++ code
- Select the device where you want to debug the app.
- Examining the evaluated expressions and variables at runtime.
It is essential to know how developers can prepare for debugging the app.
Enabling the Emulator on the device
When utilising the Emulator, the debugger is allowed by default. However, for connected devices, allowing the debugger at the Device Developer option is essential.
Running a debugging build
The Build variant can be used, which has debuggable true in build config. Generally, selecting the debug variant by default is only sufficient, which is included across all Android development projects. If you want to define debuggable modern build types, it becomes essential to attach debuggable true to the build.
It can also apply to the C/ C++ modules. If the Play Store app is dependent on the library module, which you must debug, you must also package the library through debuggable true and ensure it retains the debugging symbols.
Starting the debugging process
The debugging process can be started with the below steps:
- Have some of the breakpoints set in app code
- At the toolbar, you must select the device where you wish to debug the app. It can be done from target device breakdown menu.
If there aren’t any configured devices, you must either create an AVD using the Android Emulator or connect a device via USB.
- At the toolbar, click on the Debug button.
On seeing a dialog requesting a response whether you switch “switch from Run to Debug,” the app is operating on the device. It must restart to begin the debugging process. You can have the same Play Store app instance running by clicking Cancel Debug. You can also attach the debugger to a running app.
Android Studio can build an APK, sign it with the debug key, install it on the chosen device, and run it. If your project has C and C++ code, the Android Studio can also run LLDB debugger in Debug window for debugging the native code.
- In case the Debug window isn’t open, you can choose this option: View > Tool Windows > Debug (you can also click Debug at the tool window bar), and also click the Debugger tab.
Changing the type of debugger
Various debugger tools are needed to debug the C/C++ and Java/Kotlin code. Android Studio debugger helps choose which debugger type must be used. The Android Studio will default decide the debugger to use depending on the languages it perceives in the project.
Developers can manually choose the debugger in debug configuration. It can also be done in dialog selecting Run > Attach debugger for the Android process.
The available debug types are:
This type is selected if the developer wants Android Studio for choosing the finest alternative for debugging the code automatically. Android Studio can automatically use the Dual debug type if there is any C / C++ code in the project. Else, Android Studio can use Java debug.
This mode is selected to debug the code created in Java or Kotlin. The Java debugger will ignore breakpoints or watch the setting of the native code.
Native (available only with C/ C++ code)
This mode is selected if you use the LLDB for debugging the code. Java debugger session view isn’t available. LLDB will inspect only the native code by default. It disregards breakpoints in the Java code. If the Java code must be debugged, you must move to either the Dual or Auto debug type.
Native debugging will work on the devices with these prerequisites:
The device must support run-as.
You can assess whether it is possible. Run this command on ADB shell linked to your device:
run-as your-package-name pwd
You can change your-package-name with the Play Store app’s package name. In case the device supports run-as, there shouldn’t be any errors.
ptrace is enabled on the device.
You can verify if ptrace is enabled by running this command on ADB shell linked to the device:
If ptrace is permitted on the device, the command prints the value 0 or return an “an unknown key error”. If it isn’t supported, it will return a value other than 0.
Dual (presented with C/C++ code only)
You can select this option if you choose to toggle between debugging native code and Java. During Android development, attach the LLDB and Java debugger to the app process. Developers can inspect the breakpoints in native code and Java. They need not change the debug configuration or restart the Play Store app.
There are two tabs at the right of Debug window title. The app has C++ and Java code. Hence, one tab is to debug the Java code, while the other debug the native code.