android application debugging

Debugging Your Android Application with ADB

Burak Dönmez
Android Debugging
3 min readMay 31, 2024

--

Developing an Android application involves not only writing code but also debugging it to ensure it runs smoothly. Android Debug Bridge (ADB) is a powerful command-line tool that lets you communicate with an emulator instance or connected Android device. In this blog post, we’ll walk you through the steps to debug your application using ADB in Android Studio.

Prerequisites

  • Android Studio installed
  • A USB cable to connect your Android device to your computer
  • A basic Android application project

Try RobotQA cloud based device farm for debugging for free:

Link: Github

Step 1: Enable Developer Options on Your Device

Open Settings: Navigate to the “Settings” menu on your Android device

  1. About Phone: Scroll down and tap on “About phone”.
  2. Build Number: Find the “Build number” entry and tap it seven times. You’ll see a message saying “You are now a developer!”.
  3. Developer Options: Go back to the main “Settings” menu, and you’ll now see “Developer options” listed.

Step 2: Enable USB Debugging

  1. Open Developer Options: Go to “Settings” > “Developer options”.
  2. Enable USB Debugging: Scroll down and toggle on “USB debugging”.

Step 3: Connect Your Device

  1. Connect via USB: Connect your Android device to your computer using a USB cable.
  2. Authorize Device: If prompted on your device, authorize the connection by checking “Always allow from this computer” and then tapping “OK”.

Step 4: Verify Connection with ADB

  1. Open Terminal: Open a terminal (command prompt or shell) on your computer.
  2. List Devices: Type the following command and press Enter:
adb devices

You should see a list of connected devices. If your device is listed with a “device” status, you’re ready to go.

Step 5: Debug Your Application in Android Studio

  1. Open Your Project: Launch Android Studio and open your project.
  2. Select Device: In the toolbar, click on the device drop-down menu and select your connected device.
  3. Run the App: Click the “Run” button (green play icon) to install and start the application on your device.
  4. Set Breakpoints: In your code, click in the gutter next to the line numbers to set breakpoints where you want to pause execution.
  5. Debug Mode: Click the “Debug” button (green bug icon) to start debugging.

Step 6: Use ADB Commands for Advanced Debugging

ADB provides various commands that can help in debugging. Here are a few useful ones:

  1. Logcat: To view the log output:
adb logcat
  1. You can filter logs by application package:
adb logcat | grep your.package.name

2. Install APK: To install an APK:

adb install path/to/your_app.apk

3. Uninstall APK: To uninstall an APK:

adb uninstall your.package.name

4. Push Files: To push a file from your computer to the device:

adb push local/path /sdcard/remote/path

5. Pull Files: To pull a file from the device to your computer:

adb pull /sdcard/remote/path local/path

Troubleshooting

  • Device Not Recognized: Ensure USB drivers are installed for your device. For some manufacturers, specific drivers are needed.
  • Permissions Issues: Ensure your user account has the necessary permissions to use ADB. On Unix-based systems, you might need to use sudo.

Conclusion

ADB is an indispensable tool for Android developers. By enabling USB debugging, connecting your device, and using ADB commands, you can streamline your debugging process and ensure your app runs smoothly. With these steps, you should be well on your way to becoming proficient in debugging your Android applications using ADB.

Feel free to leave comments or ask questions if you encounter any issues. Happy coding!

--

--

Burak Dönmez
Android Debugging

Sharing experiences about mobile test automation. cofounder @roboticmobi