Learn about the various methods and utilities of debugging your Android app remotely.
The debugger in Android Studio allows you to accomplish the following and more:
- Choose a device on which to debug your app.
- In Java, Kotlin, and C/C programs, set breakpoints.
- At runtime, examine variables and evaluate expressions.
Enabling debugging on your system
Before you begin debugging, make the following preparations:
- Enable debugging on your device by doing the following:
This setting is enabled by default if you’re running the emulator. However, you must allow debugging in the device developer options for a connected device.
- Run the following debuggable build variant:
You must use a build variant with “debuggable true” as part of the build setup. Typically, you can select the default “debug” variation that comes with every Android Studio project (although it isn’t displayed in the build Gradle file). However, if you create new build types that should be debugged, you must provide the debuggable true attribute:
debuggable = true
This characteristic also applies to C/C coded modules. (The “jniDebuggable” property isn’t utilized anymore.)
You can begin a debugging session by typing:
- In the app code, create several breakpoints.
- Choose a device for debugging your app from the toolbar’s target device pop-down menu. If you don’t have devices set up, you’ll need to connect one through USB or create an AVD for utilizing the Android Emulator.
- Select Debug from the toolbar.
- When you add C and C code to your project, Android Studio additionally debugs your native code using the LLDB debugger in the Debug pane. If you see a prompt asking if you want to “switch from Run to Debug,” your app is currently running on the device and will restart to allow you to debug it. If you’d rather keep the same program running, click Cancel Debug and attach the debugger to a running app instead. Or else, Android Studio generates an APK, validates it with a debug key, installs it, and runs it on the device of your choice.
- Select View > Tool Windows > Debug (or click Debug in the tool window bar) to open the Debug window, and then click the Debugger tab.
Connect the debugger to a running application
You can debug the app already running on your device without having to restart it by following these steps:
- To attach a debugger to an Android process, select Attach debugger to the Android process.
- Select the process to which you want to connect the debugger in the “Choose Process” dialogue.
- You can select a pre-existing run to debug configuration from the “Use Android Debugger Settings” through the pop-down option. (In C and C code, this allows you to utilize existing LLDB startup, post-attach, and symbol directories.)
- Select “Create New” if you haven’t already created a run/ debug configuration. This option opens the Debug Type pop-down menu, from which you can choose a “debug type”. Android Studio chooses the best debugger for you by default, based on whether your project contains Java or C/C code.
- After that, press OK and the window for debugging pops up.
A device farm, also known as a device cloud, is a testing environment that allows QAs to test their websites and mobile apps on a large number of real devices from a distance. It provides access to both current and legacy devices from a variety of manufacturers.
You must trigger a problem or an error to debug a programme. The source code must be isolated and then remedied. A programme user needs to know how to solve the situation as it is assumed that they know about the problem analysis. The software is ready for use when the bug is fixed. Debugging instruments (called debuggers) are used in different development phases to uncover coding problems. They are used to duplicate the error conditions, then check the programme status and find out the cause.