page.title=Debugging Tasks @jd:body

In this document

  1. Tools
  2. Debug and Test Settings
  3. Top Debugging Tips
  4. Configuring Your IDE to Attach to the Debugging Port

This document offers some helpful guidance to debugging applications on Android.

Tools

The Android SDK includes a fairly extensive set of tools to help you debug your programs:

Also, see the Troubleshooting section of the doc to figure out why your application isn't appearing on the emulator, or why it's not starting.

Debug and Test Settings

With the Dev Tools application, you can turn on a number of settings that will make it easier to test and debug your applications. To get to the development settings page on the emulator, launch the Dev Tools application and open Development Settings. This will open the development settings page with the following options (among others):

These settings will be remembered across emulator restarts.

Top Debugging Tips

Quick stack dump
To obtain a stack dump from emulator, you can log in with adb shell, use "ps" to find the process you want, and then "kill -3 ". The stack trace appears in the log file.
Displaying useful info on the emulator screen
The device can display useful information such as CPU usage or highlights around redrawn areas. Turn these features on and off in the developer settings window as described in Setting debug and test configurations on the emulator.
Getting system state information from the emulator (dumpstate)
You can access dumpstate information from the Dalvik Debug Monitor Service tool. See dumpsys and dumpstate on the adb topic page.
Getting application state information from the emulator (dumpsys)
You can access dumpsys information from the Dalvik Debug Monitor Service tool. See dumpsys and dumpstate on the adb topic page.
Getting wireless connectivity information
You can get information about wireless connectivity using the Dalvik Debug Monitor Service tool. From the Device menu, select "Dump radio state".
Logging Trace Data
You can log method calls and other tracing data in an activity by calling android.os.Debug.startMethodTracing(). See Running the Traceview Debugging Program for details.
Logging Radio Data
By default, radio information is not logged to the system (it is a lot of data). However, you can enable radio logging using the following commands:
adb shell
logcat -b radio
Running adb
Android ships with a tool called adb that provides various capabilities, including moving and syncing files to the emulator, forwarding ports, and running a UNIX shell on the emulator. See Using adb for details.
Getting screen captures from the emulator
Dalvik Debug Monitor Server (DDMS) can capture screenshots from the emulator.
Using debugging helper classes
Android provides debug helper classes such as {@link android.util.Log util.Log} and {@link android.os.Debug} for your convenience.

Configuring Your IDE to Attach to the Debugging Port

DDMS will assign a specific debugging port to every virtual machine that it finds on the emulator. You must either attach your IDE to that port (listed on the Info tab for that VM), or you can use a default port 8700 to connect to whatever application is currently selected on the list of discovered virtual machines.

Your IDE should attach to your application running on the emulator, showing you its threads and allowing you to suspend them, inspect their state, and set breakpoints. If you selected "Wait for debugger" in the Development settings panel the application will run when Eclipse connects, so you will need to set any breakpoints you want before connecting.

Changing either the application being debugged or the "Wait for debugger" option causes the system to kill the selected application if it is currently running. You can use this to kill your application if it is in a bad state by simply going to the settings and toggling the checkbox.