Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio - Unable to connect to device or emulator

I have a problem running apps in Android Studio. When I press Run, the "Select Deployment Target" dialog popup occurs, but I am never able to see any emulators or devices occur. The event log prints out the following and repeats indefinitely:

5/6/18
12:40 PM    Gradle sync started

12:40 PM    Project setup started

12:41 PM    Gradle sync finished in 49s 932ms

12:41 PM    Executing tasks: [:app:generateDebugSources]

12:41 PM    Gradle build finished in 15s 765ms

12:44 PM    Unable to open connection to: localhost/0.0.0.0:5037, due to: java.net.ConnectException: Connection refused

12:44 PM    Connection attempts: 1

12:44 PM    Unable to open connection to: localhost/0.0.0.0:5037, due to: java.net.ConnectException: Connection refused

12:44 PM    Connection attempts: 2

12:44 PM    Unable to open connection to: localhost/0.0.0.0:5037, due to: java.net.ConnectException: Connection refused

12:44 PM    Connection attempts: 3

12:44 PM    Unable to open connection to: localhost/0.0.0.0:5037, due to: java.net.ConnectException: Connection refused

12:44 PM    Connection attempts: 4

12:44 PM    Unable to open connection to: localhost/0.0.0.0:5037, due to: java.net.ConnectException: Connection refused

12:44 PM    Connection attempts: 5

I am able to run react-native projects using the command line, but when using Android Studio directly, this occurs.

I have tried creating new projects in Android Studio and still have the same results. I believe this started to happen once I updated from Android Studio 3.0 to 3.1.

Any ideas to fix this issue or get more information?

Thanks.

System Information:

MacOS High Sierra 10.3.14 Macbook Pro (Late 2011)

Software Information:

Android Studio 3.1.2 Java 9.0.4

like image 907
Tyrice Clark Avatar asked Dec 08 '22 14:12

Tyrice Clark


2 Answers

I had the same issue, i fixed it by removing 0.0.0.0 mapping in /etc/hosts.

Earlier i had a mapping 0.0.0.0 localhost in /etc/hosts file.

like image 160
Ayushya Avatar answered Dec 17 '22 14:12

Ayushya


I also had a similar issue on Mac and fixed it by appending the line 127.0.0.1 localhost to /etc/hosts

like image 39
littlebear333 Avatar answered Dec 17 '22 15:12

littlebear333