32

I am trying to debug the android source using Eclipse by following the instructions found at:

http://source.android.com/using-eclipse

I have downloaded the source, and gotten it to build. I follow the directions in the link above and everything is fine until I run the ddms command. At this point, if Eclipse is running I get the error 'Could not open Selected VM debug port (8700)'. If I close Eclipse, then ddms runs with no problem, and I can the the processes on the emulator. However, if I now open Eclipse, I get the same error.

In any case, no matter what I do, if I attempt to remote debug, it always fails with 'Failed to connect to remote VM'.

Any ideas?

Thanks

4
  • Keep in mind that the procedure you are following allows you to debug the Android platform code. There are much easier ways to debug application code.
    – Tim Kryger
    May 10, 2010 at 6:18
  • 1
    I would be MOST interested in a easier way. However, my goal is to be able to debug native code. I know how to debug java.
    – John Gaby
    May 10, 2010 at 14:30
  • 1
    This procedure won't help you debug native code. For that you need to use GDB and follow these steps.
    – Tim Kryger
    May 10, 2010 at 15:08
  • 1
    If you are using Android Studio, you could use Android Device Monitor, and DDMS is one part of it.
    – Sam003
    Mar 6, 2015 at 16:55

12 Answers 12

19

It looks like you have two problems:

  1. You are trying to run DDMS twice. You do not need to run the free standing version of DDMS since there is version of it integrated in Eclipse as part of the Android plug-in. If you change to the DDMS perspective in Eclipse, I'm sure you will find that all the same features are available.

  2. You have not told DDMS which VM you want to debug at localhost:8700. Before you attempt to establish your remote debug connection, you must go to the DDMS perspective and click on the system_process (or whatever process you want to debug).

7
  • Thanks for the response. I thought I might not need DDMS,so I tried debugging without it, but I could still not get it to work. Here is what I am doing. 1) The Android emulator is running, and the process I want to debug is running. 2) Start Eclipse 3) Choose Run/Debug Configurations from the menu 4) Choose the "android-debug" options under "Remote Java Application". 4) Set Host to 'localhost' and Port to 8700. 5) Click Debug 6) I get get the message 'Failed to connect to remote VM' Any ideas? Thanks (Why am I restricted to so few characters in these responses?)
    – John Gaby
    May 10, 2010 at 13:30
  • Also note that if Eclipse is not running and I run DDMS, it does successfully connect to the emulator, and I can see all the processes.
    – John Gaby
    May 10, 2010 at 13:34
  • I'm not sure what "android debug" option under "Remote Java Application" you are talking about but I still think your problem is that you haven't selected the process you want to debug in DDMS and you really should just use the DDMS integrated into Eclipse.
    – Tim Kryger
    May 10, 2010 at 15:06
  • I appreciate your help! I would love to use the DDMS that is integrated into Eclipse, but I apparently don't know how to do that. I am using the "Run Configurations" that is on the "Run" menu. This brings up a "Debug Configurations" dialog. In the panel on the left there is a "Remote Java Application" entry. If I open it, there is an 'android-debug' options. I select that option. I take it that I should be doing something else? Can you point me in the right direction. Thanks.
    – John Gaby
    May 10, 2010 at 15:22
  • Assuming you have installed the Android plug-in already, open Eclipse and select Window->Open Perspective->Other... then pick DDMS.
    – Tim Kryger
    May 10, 2010 at 15:29
18

The Windows Host file that is messed up is at C:\WINDOWS\system32\drivers\etc, and it should contain this line:

127.0.0.1 localhost

If that doesn't work, then try making the following changes in Eclipse.

Under Window -> Preferences -> Android -> DDMS:

  • Set Base local debugger port to "8601"
  • Check the box that says "Use ADBHOST" and the value should be 127.0.0.1
2
  • 2
    This looked likethe solucion to being able to run apps in both, android studio and eclipse but don't run neither Jan 23, 2015 at 14:50
  • because of this now i'm able to use AS and eclipse together, because my AS opens new window for each project import(don't know the reason), and my system(even with 8Gb RAM) can't handle two AS running together Mar 11, 2016 at 5:46
7

I solved it by ending the process "adb.exe" through Task Manager and then reloading the SDK through Windows->Preference..I am running Eclipse Indigo on Win 7 64-bit.

1
  • I am not on Windows, but perhaps just adb kill-server?
    – Maroloccio
    Oct 5, 2015 at 14:48
5

I was having that problem too (Windows 7), even though my /Windows/system32/drivers/etc/hosts file already had 127.0.0.1 localhost in it.

I tried changing the ADBHOST info & port in the eclipse Preferences, but that didn't do anything.

netstat -b shows '127.0.0.1' as the source address for adb and the emulator, but always lists my machine host name as the 'foreign address.' On a hunch, I tried debugging with my machine not connected to any network (no WiFi, nothing plugged in)... and it worked! (DDMS was able to connect to the VM on the emulated device and I was able to debug just fine.)

I think that messages sent by DDMS &/or adb are not staying on my local machine (they're getting sent to my local router). (It's just a guess; I don't know how to conclusively test that.) IOW, loopback wasn't working as it should.

Since I already had 127.0.0.1 in my localhosts, I added the local subnet address of my machine into my hosts file, guessing that DDMS/adb might be using that address (vs. 127.0.0.1). That seemed to solve the problem for me.

So now my hosts file has these lines:

127.0.0.1       localhost
::1             localhost
192.168.1.102       localhost

(The local IPv4 address for my machine is 192.168.1.102 . You can check yours with the ipconfig command.)

(I came across some webpages that how to set up a virtual network adapater for Windows that handles loopback, e.g. Setting up a Microsoft Loopback Adapater (from Oracle Distilled), but haven't had time to take that in and see if that's a viable solution to all of this, too.)

5

I solved it by opening the windows Task manager and closing the process "adb.exe". Then close eclipse and reopen it. It will start properly without any error.

2
  • How is your solution different to the one posted by Pallav?
    – stuXnet
    Oct 6, 2014 at 8:53
  • I agree it is very similar...infact i corrected mine by following his instruction only ...hence i upvoted his answer also ... but when i was trying to reload the SDK, it was showing some error (which i dont exactly remember)... hence i just restarted eclipse. I posted this answer as a variation of pallav's solution. I am sorry for forgetting to mention his name in it.
    – sid_09
    Oct 6, 2014 at 14:06
2

This is for reference. But I guess this might match your case.

Port 8700 is very special port for ddms; there's no way to change the port. Port 8700 is used for aggregating the packet from every Dalvik VM.

There will be two cases;

case 1) If you set "Base local debugger port"(in Eclipse ddms preference dialog) to 8700, then you'll see error - "Can't bind to local 8700 for debugger", everytime ddms initiated. But no problem, because if ddms couldn't bind 8700 to the first VM, then will be connected to 8701, and then 8702 and so on.

case 2) Even if you set "Base local debugger port"(in Eclipse ddms preference dialog) to 8600, you may see error - "Can't bind to local 8700 for debugger", in some cases. Because, if your device have more than or equal to 100 dalvik VMs, port assigning to each VM starting from port 8600 may reach to 8700 port. But, no problem occurs same as in case 1).

So, if you really don't want to see the error, you have to set the "Base local debugger port"in Eclipse ddms preference dialog to 8701 or above.

Stand-alone ddms or android monitor uses different setting file from Eclipse, so it may not make this kind of problems.

~

1

Had the same problem, different port numbers in the console output (where I launch ddms) caught my attention

Then from the documentation, I learned that 8600 is the default base port number. Every new process uses the next available port (8601,8602,...). In addition, 8700 is the default active port number (indicating the currently selected process in the dbms)

Here are the steps to debugging Android source+applications

  1. Run emulator
  2. Run ddms
  3. Open Eclipse (It may complain about being unable to connect to 8600. This is because, when Eclipse starts up and if you have Android plugin, it boots up ddms. Since we already have a ddms connected to the device, trying to connect for a second time won't work)
  4. In the ddms, pick a thread you want to debug (when you highlight it, it will show you the ports that it is using as well as 8700 (e.g. "8649 / 8700"). This means you can use both ports to connect to this process
  5. From eclipse, using the remote debugging configuration, connect to any process you wish (easiest is to highlight the process from within ddms and then connect to 8700)
1

This type problem occurs when you are using another VM with the same port number. As an example you are using Android SDk full bundle which you have downloaded from the android developer website. Now you want to use Eclipse and plugged in ADT, SDK. There is a high probability to happen this type of error. It happened to me. To overcome this difficulties you can do :
Window-Preferences-Android- Choose DDMS- Change base local debugger port(use 8601 instead of 8600).
It can work. Thanks

1

I done it by restarting my computer

0
0

Just for completeness: (on win 7/Vista) not only you have to make sure line

127.0.0.1 localhost

is present in

C:\WINDOWS\system32\drivers\etc

you also need to comment out all your other local virtual hosts resolving from 127.0.0.1. This is most probably the case if you're developing web stuff on the same machine and set it up earlier for different host names looping back to local.

0

I solved the problem by ONLY close android studio so the eclipse can get ddms

0

When I execute monitor in $ANDROID_HOME/tools/monitor on Ubuntu 16.04, it shows

Could not open Selected VM debug port (8700). Make sure you do not have another instance of DDMS or of the eclipse plugin running. If it's being used by something else, choose a new port number in the preferences.

I tried to do the following:

Under Window -> Preferences -> Android -> DDMS:

Set Base local debugger port to "8601" Check the box that says "Use ADBHOST" and the value should be 127.0.0.1

But it still pops up the dialog.

Then I did the following:

gongzelong@gongzelong:~$ netstat -apn |grep 8700
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
tcp        0      0 127.0.0.1:8700          0.0.0.0:*               LISTEN      5044/java       
gongzelong@gongzelong:~$ kill -9 5044
gongzelong@gongzelong:~$ monitor

By doing this, it solved my problem.

Do not know why, but it works for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.