Unable to open connection to: localhost/127.0.0.1:5037, due to: java.net.ConnectException: Connection refused: connect

Viewed 5040

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

2 Answers

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.

Related