Monday, October 3, 2011

AIR extensions in Java for Android Part 5 -- debugging the Java code

I'm sure there's more than one way to do it. This is just one way, using Eclipse/Flash Builder and the Android DDMS plug-in. I've tried the following on a Mac, but haven't tried on a PC yet.

Do all of the following:
1. Set the AIR application to be debuggable in Android's eyes by setting the Android application debuggable attribute to true ( in the AIR application descriptor):
            <manifest android:installLocation="auto">
                <application android:debuggable="true"/>

2. Create a dummy Android project. Do not create an activity. Set the package to be the same as the AIR application ID. Add the Java extension project to the build path. This dummy project tricks the DDMS debugger into looking here for your Java.

3. Add a call to the Android API, android.os.Debug.waitForDebugger() somewhere before you want to start debugging.

4. Set a breakpoint after the waitForDebugger() call.

Now rebuild and launch your project on a device. In the DDMS perspective in Eclipse, select the app process in the devices menu (under your phone or tablet). Click the green bug icon to enable debugging of the process.

When your code hits a breakpoint it should stop and Eclipse should show the break pointed line of your Java code.

Another helpful Android API for debugging is android.utils.Log. This class lets you easily put messages into the system log so you can view them with adb logcat.


  1. Am I supposed to launch the dummy project on the device? If I attempt to do this I get errors that the resource directory does not exist. Is there a way to correct this?

  2. No, you don't launch the dummy project.


Note: Only a member of this blog may post a comment.