My Android Studio 3.4.1 shows the error below (as in screenshot) when running the app
Unable to open connection to: localhost/127.0.0.1:5037, due to: java.net.ConnectException: Connection refused: connect
I have my android phone connected to my Windows 7 PC, but Android Studio still show the error. I did click on "Restart ADB server" but problem persists.
Thank you
Use 10.0.2.2 to access your actual machine.
When you use the emulator, localhost (127.0.0.1) refers to the device's own loopback service, not the one on your machine as you may expect.
You can use 10.0.2.2 to access your actual machine, it is an alias set up to help in development. You can read more from Here
Also, remember to access localhost from your real device your system and mobile need to connected to the same wifi/network.
I had the similar problem on Ubuntu: but I found out also that my phone keep reconnecting in IDE.
Solution - just to give permission change things to the android studio folder.
Hi i am developing and android application which communicates with the backed server. I Tested my application inside my Working environment its working fine... I am able to connect to the server and i got the response...
But when i went for testing in my clients environment, i was unable to connect to the back end server.. I used their LAN to access web server...
The problem i am having is Unknown Host name..
Insted of giving the host name i gave the ip address to the host and my application got the response successfully from the server, but if i change the ip address to the DNS i was unable to connect..
I Tried several options
Tried to set the host ip address in Eclipse -> Window -> Preference -> Android -> Launch. but it didnt work.
I Tried to launch the emulator from the command line using the following command
emulator -avd MYAVD -dns-server X.X.X.X
this one also didn't work.
Since my time is limited to deploy i need help.
I tried all the possible options given on net and on this site, but none of them worked.
I am getting:
Launch error: Failed to connect to remote VM. Connection timed out.
when I am trying to debug my application on my mobile device.
the application runs properly with out any issue when I am running normally
I have used at lease these links by now:
How to resolve "Waiting for Debugger" message?
Eclipse issue - Launch error: Failed to connect to remote VM. Connection timed out
Eclipse Error: "Failed to connect to remote VM"
Launch error: Failed to connect to remote VM
https://forums.oracle.com/forums/thread.jspa?threadID=653343
None of the above seem to work.
Go to Window -> Preferences -> General -> Network Connections, and check if there is any proxy set here, change the 'Active Provider' to be 'Direct' and try again.
I dont know why, but this works for me:
First Run(or Debug) your application in an emulator and then Debug the application on the device (without closing the emulator).
let me know if this works for you.
I've been having the same frustrating problem. I finally found something that is working for me: making sure localhosts is being resolved correctly (and really explicitly).
Test to see if it works when your development machine is not connected to the net (no WiFi, no network cables). If it does work under those conditions, then it may be that you need to make sure that addresses are resolving to localhost properly. The messages that DDMS and adb.exe use for debugging and communicating to the VM must properly resolve to localhost on your machine. (Yes, it's odd that other commands using DDMS & adb work just fine but debugging doesn't. Seems that something in DDMS or adb needs to be standardized so they all work under the same conditions.)
If you need to make sure that things are resolving to localhost properly:
1) Make sure that this line is in your /Windows/System32/drivers/etc/hosts [windows] (or etc/hosts [*nix] file:
127.0.0.1 localhost
(you can have any amount of whitespace between "127.0.0.1" and "localhost")
2) If that doesn't work, then you may need to also add your PC's IPv4 address to the hosts file, and resolve it to localhost. (You can find out the IPv4 address for your machine with the ipconfig command.) If, for example, your machine's IPv4 address is 192.168.1.100 then you'd add the line
192.168.1.100 localhost
to your hosts file. (You can add it below the "127.0.0.1 localhost" line in the file.)
I had (1) in my hosts file but it still wasn't working (unless my PC wasn't connected to the net). I tried (2) on a bit of a guess, and that worked for me.
BTW: You can verify that adb (and your emulator if you're running one) is listening on ports by using the netstat -b command. (Note that on Win7 you need admin privileges for the -b option. I open a command window using "Run as Administrator.")
May seem like an obvious answer but make sure you don't have two emulators running - 5554; 5556; ... The debugger has difficulty setting the port when it doesn't know which one to connect to.
How to Enable Internet Connection Through Proxy in Android in Windows?
http://www.coderanch.com/t/462906/Android/Mobile/connect-internet-behind-proxy
In the earlier versions of Android emulators (up to version 1.1r2), you were required to make an entry in the system table of“com.android.provider.setting.db” database and/or start the emulator with –http-proxy switch supplying it the IP address and port number of your proxy.
These methods however, have become obsolete and don’t work with SDKv1.5.
Step 1: On emulator, go to:
Home->Menu->Settings->WirelessControls->MobileNetworks->Access Point Names->T-mobile US->set Proxy IP and Port#
Step 2: Now the next time you go to a web address, the browser will prompt for your user-id and password. Enter your credentials and you should be good to go.
Reference: http://groups.google.com/group/android-beginners/b…d4f948c4ed622#5ced4f948c4ed622” target=”_new” rel=”nofollow”>
Steps for Android 2.2
1) Create an emulator with name say android_2.2_emulator using AVD manager in eclipse.
2) Create a batch file (.bat) with following command and a keep a handy shortcut.
emulator -avd “android_2.2_emulator” -http-proxy “your_proxy_url”:”port”
3) Run the batch file before starting the eclipse IDE, so that the emulator session will have internet connection.
That’s it.
Give your Android device a static IP. Ensure both the Windows computer and the Android device are on the same subnet. Set the IP of the android device as the gateway for the Lan connection on the Windows computer.
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
It looks like you have two problems:
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.
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).
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
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.
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.)
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.
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.
~
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
Run emulator
Run ddms
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)
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
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)
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
I done it by restarting my computer
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.
I solved the problem by ONLY close android studio so the eclipse can get ddms
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.