Home > Process handling > Debug a remote Android process in Eclipse

Debug a remote Android process in Eclipse

Most people that are developing Android applications using Eclipse will probably use the Eclipse ADT plugin. The plugin offers a lot of functionality, including

  • Debugging features, via it’s integration with the Dalvik Debug Monitor Server (DDMS)
  • Emulator control from the Eclipse workspace
  • XML Validation for Android specific files (strings, views,  menus , ….)
  • Project Wizards, to facilitate the creation and packaging of your Android app

In this short article, we’ll be discussing the debugging of remote android processes (the processes defined in your manifest using the android:remote attribute).

Android Eclipse ADT Plugin

Each component in the Android stack (Activity, Service, Receiver and Provider) is defined in the manifest file of your application. For example, an Activity is usually defined like this :

        <activity android:name=".LocalActivity"
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />

The activity here will run in the main thread of the application process. If you put a breakpoint in your onCreate method, you’ll see this in the debugger :

Eclipse onCreate Debug

Eclipse onCreate Debug

A few things we should note here :

  • We see the debugger is connected to the DalvikVM via localhost:8627.
  • Our Activity is created in the main application thread (identified by <3> main).

If we go to the DDMS perspective, we see the following :

DDMS perspective

DDMS perspective

As you can see, we see our emulator (identified by emulator-5554) hosting a number of processes including the process that is currently running our application (identified by our application package com.ecs.android.sample.remoteprocess). Here, you also see the debug port that allows us to attach a debugger (port 8627). The green bug next to our application process indicates that a debugger is attached.

From this screen, it is possible to start debugging other applications (represented by different processes), providing you have a source project in your workspace. In the example here, I have an android project that hosts the application identified by the com.ecs.latify package, so I can select com.ecs.latify, and hit the green bug to start debugging the selected process. As soon as you do this, 2 things will happen :

A green bug will be put alongside the process.

DDMS perspective

DDMS perspective

Your Eclipse debug perspective will now have a second Android application ready to be debugged.

debug second app

debug second app

We’ll now add a button to our application that launches a second activity, but this time, we’ll configure the activity to run in a different process using the android:process attribute in the manifest.

        <activity android:name=".RemoteActivity"

We’ll put a breakpoint in the onCreate() method of the RemoteActivity and launch the application in debugmode. You’ll notice that the debugger will not be suspended when the second activity is shown. The reason being that the second activity runs in a totaly different process. If we switch back to the DDMS perspective, we’ll see our RemoteActivityProcess. Notice how it runs as a seperate process, using a seperate port (8631).

DDMS perspective remote process

DDMS perspective remote process

In order to hook up a debugger, one would expect that selected the process, and clicking on the green bug would be sufficient (like we did in the previous section). Unfortunately, due to reasons unclear to me, Eclipse shows the following dialog :

The only way to debug this process is by creating a remote java application in eclipse, pointing to the port (8631) as defined the DDMS process overview.

Only then will we able to suspend the debugger on the breakpoint that was put on the activity configured to run in a remote process.

  1. Bruno Nardin
    January 7th, 2011 at 10:58 | #1

    very usefull article , I use this method to debug a remote service..

    Thanks you very much!!!

  2. Tomcat
    February 7th, 2011 at 06:57 | #2

    I have been developing remove service but failed to attach debugger so to debug that code
    I changed to run in same process. And I found your blog to solve this issue. Finally now I can
    freely debug my remove-processed-service without changing anything. This is great.

    Thanks a lot. You really saved me.

    • admin
      February 7th, 2011 at 15:56 | #3

      Glad to be of service !

  3. Michel
    April 12th, 2013 at 10:40 | #4

    I’m trying to debug a widget, sometimes this works but sometimes the widget is not in the list of processes on my device, any suggestions ?

  1. No trackbacks yet.