Kleiber J. Perez
Kleiber J. Perez

Reputation: 293

Unable to open debugger port : java.net.ConnectException "Connection refused"

I'm using Android Studio v1.0.1 to build an app in macOS Yosemite 10.10. When I try to debug the app, it installs correctly but has the error

Error running [app]: Unable to open debugger port : java.net.ConnectException "Connection refused"

When I run the DDMS, it shows the connected devices and the process. The trouble occurs just when trying to debug in Android Studio.

In other forums, I've found that something could have changed the port of the debugger, but that doesn't solve my issue.

Upvotes: 23

Views: 66513

Answers (12)

prasuna_16
prasuna_16

Reputation: 31

I encountered same issue when running application on a physical device.

Just connect your PC and mobile to the same WiFi Network and disable the firewall of your PC. It worked for me.

Upvotes: 0

androidmalin
androidmalin

Reputation: 919

I my case mackbookpro: 20:21 Can't bind to local 8600 for debugger

I find /ect/hosts file is blank. so,I add the default hosts config to /etc/hosts file, It works fine.

127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost

Upvotes: 1

Ramesh Thamizhselvan
Ramesh Thamizhselvan

Reputation: 181

For Windows user you can kill the port by using the following command ..

Step 1:

Open the cmd (note: you may need to run it as an administrator, but this isn't always necessary), then run the below command:

netstat -ano | findstr :PORT_NUMBER

enter image description here

Step 2:


Syntax:
taskkill /PID PORT_NUMBER /F

cmd:
taskkill /PID 5005 /F

enter image description here

Upvotes: 1

Bakavani
Bakavani

Reputation: 131

It was a /etc/hosts file issue for me as well, I changed the following line (dont know why it was working before ... after upgrade to studio 3.1.3 it stopped working though!)

127.0.1.1    localhost 

to

127.0.0.1    localhost 

Upvotes: 2

user4203986
user4203986

Reputation:

I also solved this by making 127.0.0.1 in my Mac hosts file NOT point to a custom domain. One thing to note, I had 2 host files, one in "/" and one "/etc". One in "/etc" was actually used.

Upvotes: 0

Saravanan Kathiresan
Saravanan Kathiresan

Reputation: 13

For me none of the above solved and got stuck in this for months until I figured this solution. I had a modified version of my HOST file in my mac machine like pointing the IP 127.0.0.1 to a custom domain like www.mymac.com. Once I reverted that then I am able to debug. Yes!!! hope this helps for some one.

Upvotes: 1

Shubham Raitka
Shubham Raitka

Reputation: 1052

I had this problem when I was using a real device, I just unplugged the USB cable and then again plugged it in and it worked. In case of emulators, I guess restarting the emulator will work. This works because disconnecting the device/emulator closes all connected processes, and then you start your required process.

Upvotes: 3

Anjan Kant
Anjan Kant

Reputation: 4316

Restarted my Android Studio, worked for me.

Upvotes: 4

Dhaval Jivani
Dhaval Jivani

Reputation: 9697

My problem Solved by below steps:

1. Invalidate Caches/Restart Android studio

2. Restart you Emulator.

Done for me.

Upvotes: 9

bonnyz
bonnyz

Reputation: 13558

Your debug port is probably busy (in use by another process). You can kill all the process associated with the ADB debug port (8601 or higher) using this:

fuser -k 8601/tcp 

UPDATE:

Under OSX, lsof should do the job in substitution of fuser:

lsof -i :8601

Upvotes: 24

VicX
VicX

Reputation: 711

I have also met this problem. and I think the my solution may help others, so I post it here.

First, you should know what will cause "connection refused" problem. Usually there are two possible reasons:

  1. This particular server is not started.
  2. The server is started but not accept any connection.

As for your problem, I suggest you to first start your Android Device Monitor(DDMS) from your android studio, and DO NOT CLOSE IT.

Then in the DDMS, you can select the package you want to debug and "Update Threads", and now you can debug this application in your studio.

Upvotes: 15

Andre
Andre

Reputation: 647

You can use netstat utility to see what is listening on what ports and, if you are quick, what tries to connect to what ports. This will help to to ensure that you have your process listening on a debugging port and confirm its number.

Upvotes: 0

Related Questions