Mobile Development 15 min read

Android Debugging Techniques: Operations, Practices, and Principles

The guide explains Android debugging fundamentals, covering run and attach modes, essential operations like stepping and breakpoints, best practices for inspecting variables and reducing compile time, the underlying ADB and JDWP protocols, and troubleshooting common issues such as breakpoint loss and port conflicts.

NetEase Cloud Music Tech Team
NetEase Cloud Music Tech Team
NetEase Cloud Music Tech Team
Android Debugging Techniques: Operations, Practices, and Principles

This article provides a comprehensive guide to Android debugging, an essential skill for developers that significantly improves development efficiency.

The content covers four main areas:

1. Debug Operations : Introduction to Debug Run and Attach to Process modes, with detailed explanations of common debugging operations including Show Execution Point, Step Over, Step Into, Step Out, Drop Frame, Run to Cursor, and Evaluate Expression. The article also covers different breakpoint types: line breakpoints, field breakpoints, exception breakpoints, and method breakpoints.

2. Debug Practices : How debugging helps developers through "viewing information" and "reducing compilation times". Topics include viewing local and global variables, examining stack traces, runtime code modification using setValue and Evaluate Expression, log breakpoints, conditional breakpoints, exception breakpoints, multi-threaded debugging, and debugging Release packages using ADB forward and JDWP protocols.

3. Debugging Principles : The debugging process relies on ADB (Android Debug Bridge) and JDWP (Java Debug Wire Protocol) for communication between the debugger and the virtual machine. The article explains the ADB architecture consisting of ADB Server, ADB Client, and ADB Daemon, and provides detailed analysis of JDWP protocol packets including command packets and reply packets with their header structures.

4. Common Issues : Solutions for breakpoint disconnection on certain devices, "Attach to Process" failures due to port conflicts, and performance issues when using method breakpoints.

Key commands mentioned include: adb shell am set-debug-app -w --persistent 包名 for enabling debug wait mode, adb shell am clear-debug-app for disabling it, adb shell dumpsys activity top | grep ACTIVITY for finding the current activity, and adb forward tcp:5005 jdwp:PID for connecting the debugger to a process.

mobile developmentbreakpointsandroid-studioADBandroid debuggingDebugging PrinciplesjdwpMulti-threading Debugging
NetEase Cloud Music Tech Team
Written by

NetEase Cloud Music Tech Team

Official account of NetEase Cloud Music Tech Team

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.