If you are not using Eclipse to develop, you can still take advantage of all the tools that the Android SDK provides for debugging. A basic debugging environment consists of:
You need to obtain a JDWP-compliant Java debugger to properly debug your application. Most Java IDEs will already have one included, or you can use a command line debugger, such as JDB, if you are using a simple text editor to develop applications.
Starting a debugging environment
A Java Debugger assists you in finding problems with your code by letting you set breakpoints, step through execution of your application, and examine variable values. Since you are not using Eclipse, you have to manually start up the debugging environment yourself by running a few tools that are provided in the Android SDK. To begin debugging your application, follow these general steps:
- Load an AVD with the Android emulator or connect a device to your computer.
- Start DDMS from the sdk
/toolsdirectory. This also starts ADB if it is not already started. You should see your device appear in DDMS.
- Install and run your
.apkfile on the device or emulator. In DDMS, you should see your application running under the device that you installed it to.
- Attach your debugger to the debugging port 8700, or to the specific port shown for the application in DDMS.
Configuring Your IDE to Attach to the Debugging Port
DDMS assigns 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.