Introduction / Why This Is Needed
Debugging is a key stage in Android app development. Without effective use of debugging tools, finding and fixing errors becomes a chaotic process that consumes hours. This guide will give you a systematic understanding of the essential tools: ADB, Logcat, and Android Studio's built-in debugger. You'll be able to quickly find causes of crashes, analyze data flow, and test code in real-world conditions on a device.
Requirements / Preparation
Before you begin, ensure you have the following installed:
- Android Studio (version Arctic Fox 2020.3.1 or newer) with Android SDK and Android SDK Platform-Tools components.
- An Android device (version 5.0 and higher) with "USB debugging" enabled (found in Settings → Developer options).
- A USB cable (preferably a high-quality one that supports data transfer).
- For Windows: installed USB drivers for your device. For Linux: configured udev rules.
- Basic knowledge of working with a terminal/command line.
Step 1: Enable USB Debugging on the Device
On the device itself, you need to activate developer mode and allow debugging.
- Go to Settings → About phone.
- Find the "Build number" item and tap it 7 times. A notification "You are now a developer!" will appear.
- Go back to the main settings menu and find the new "Developer options" (or "For developers") section.
- Inside, enable the "USB debugging" toggle.
⚠️ Important: When connecting the device to the computer for the first time, a dialog will appear asking "Allow USB debugging?". Be sure to check "Always allow from this computer" and click "OK".
Step 2: Prepare the Computer: Install Drivers/Rules
Without the correct drivers, the computer will not see the device.
For Windows:
- Download the drivers:
- Universal: Google USB Driver (via Android Studio's SDK Manager).
- Manufacturer-specific: Drivers from the Samsung (Kies), Xiaomi (Mi PC Suite), Huawei, etc. websites.
- Install the driver via Device Manager (Win + R →
devmgmt.msc). - Find the unknown device (usually with a yellow exclamation mark) under "Other devices" or "Android Device".
- Right-click → "Update driver" → "Browse my computer for driver software" → point to the folder with the extracted driver.
For Linux (Ubuntu/Debian):
- Create the rules file:
sudo gedit /etc/udev/rules.d/51-android.rules - Paste the rules for your manufacturer. For example, for general Google devices:
Full list of vendor IDs: https://developer.android.com/studio/run/linux-usbSUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev" - Set permissions and reload udev:
sudo chmod a+r /etc/udev/rules.d/51-android.rules sudo udevadm control --reload-rules sudo udevadm trigger
Step 3: Check Device Connection via ADB
Now you need to confirm the connection is established.
- Open a terminal (Linux/macOS) or Command Prompt/PowerShell (Windows).
- Navigate to the platform-tools folder (usually
~/Library/Android/sdk/platform-tools/on macOS orC:\Users\<User>\AppData\Local\Android\Sdk\platform-tools\on Windows) or add it to your PATH. - Run the command:
adb devices - Expected output:
If it saysList of devices attached 0123456789ABCDEF deviceunauthorizedinstead ofdevice, check the dialog on the device. If the device is not listed — return to Step 2.
Step 4: Configure the Project in Android Studio
- Open your project in Android Studio.
- Ensure the
build.gradlefile (module level) specifies the correct compileSdk and minSdk versions. - On the toolbar at the top right, find the "Select Deployment Target" dropdown.
- In the window that opens, your device should appear under "Connected Devices". Select it and click "OK".
- To debug, click the "Debug" button (bug icon). The app will install and launch in debug mode.
Step 5: Use Logcat to Analyze Logs
Logcat is your primary source of information about what's happening in the system and your app.
- In Android Studio, open View → Tool Windows → Logcat.
- At the top of the Logcat window, select:
- Device: your connected device.
- Process: your app's process (usually
com.example.yourapp). You can select<your_package_name>orNo Filtersfor all. - Log level: set to
DebugorVerbosefor maximum detail,Errorfor errors only.
- To quickly find your app's logs, use a filter:
- By tag: enter
tag:MyAppTag(if you use a specific tag in code). - By package: enter
package:com.example.yourapp.
- By tag: enter
- Look for lines with
E/(Error),W/(Warn), orAndroidRuntime(for unhandled exceptions). Click on an error line — Android Studio will jump to the corresponding line of code (if sources are available).
Step 6: Run the App in Debug Mode
This is the main method for step-by-step analysis.
- In the code editor, set breakpoints: click in the gray area to the left of the line number where you want execution to stop (a red circle will appear).
- Click the "Debug" button (bug icon) on the toolbar.
- The app will launch on the device. Once execution reaches a breakpoint, it will pause.
- The debugger window will appear at the bottom:
- Frames: call stack.
- Variables: current variable values in context.
- Watches: add an expression to monitor.
- Use the execution control buttons:
- Resume (F9): continue to the next breakpoint.
- Step Over (F8): execute the current line and move to the next.
- Step Into (F7): step into the method called on the current line.
- Step Out (Shift+F8): step out of the current method.
- You can change variable values directly in the debugger to test different scenarios.
Verification
After completing the steps, you should be able to:
- See your device in the
adb deviceslist. - Successfully launch the app on the device from Android Studio.
- See your app's logs in Logcat, filtered by package.
- When breakpoints are set — pause code execution and inspect variable states.
If all points are working — the debugging environment is set up correctly.
Possible Issues
Issue: Device does not appear in adb devices or in Android Studio.
Solution:
- Reconnect the USB cable, try a different port.
- On the device, go to Settings → Developer options and turn "USB debugging" off and on.
- Restart the
adbserver:adb kill-server adb start-server adb devices - For Windows: check in Device Manager that the device is recognized as "Android Composite ADB Interface" without errors. Update the driver manually.
Issue: No logs from my app appear in Logcat.
Solution:
- Ensure you are using
Log.d(tag, message)or similar in your code, notSystem.out.println. - Check the Logcat filter: set the level to
DebugorVerbose, try clearing the filter (No Filters). - Ensure the app is running on the same device selected in Logcat.
- On some devices (especially MIUI), you additionally need to enable "Enable USB debugging (Security settings)" in Developer options.
Issue: Breakpoints are ignored, the app does not stop.
Solution:
- Ensure you launched the app via "Debug", not "Run" (the bug icon).
- Check that the breakpoint is active (red circle, not a gray circle with an outline). Gray means the code will not be loaded (e.g., a breakpoint in an unused class).
- Clean the project (Build → Clean Project) and restart the debug session.
- If the app is already running, stop it completely and launch it again in debug mode.