5

I'm taking the first steps in android development. Started working through this guide https://developer.android.com/training/basics/firstapp/running-app and the error occurred when the program is run on the device.

First of all, my device is not in the list of connected in Android Studio:

First of all, my device is not in the list of connected in Android Studio

adb devices doesnt see my device when Android Studio is running, but if I close Android Studio, adb devices shows my device

When Android Studio starts, it shows an error and logs all the time this error flashes:

When Android Studio starts, it shows an error and logs all the time this error flashes

I tryed this this solution but it didnt solve my problem:

I dont know, why Android Studio try to connect to weird address localhost/127.0.0.7:5037?

Zoe
  • 27,060
  • 21
  • 118
  • 148
Evgeny Naumov
  • 347
  • 1
  • 4
  • 15
  • I'm also having this issue with an Android 9 Pie phone (Xiaomi Redmi Note 8T). Would maybe starting a bounty help to find solution? –  May 01 '20 at 17:31
  • This solution was helped for me. https://stackoverflow.com/a/51367891/7803911 – Evgeny Naumov May 01 '20 at 18:04
  • sorry but no, it didn't help me, I've posted [my solution](https://stackoverflow.com/a/61549365/11323942) instead, –  May 01 '20 at 19:49

7 Answers7

3

I forgot. I edited /etc/hosts and commented line

#127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4

After uncommented the line and restarted the Android Studio, I've solved my problem.

Evgeny Naumov
  • 347
  • 1
  • 4
  • 15
1

in my case in /etc/hosts I had the following line that i removed

0.0.0.0 localhost
sajad abbasi
  • 1,988
  • 2
  • 22
  • 43
0

I've catched this error under:

Android Studio 3.1.4
Android Debug Bridge version 1.0.32, Revision eac51f2bb6a8-android

Also i'm working in the office with some active firewall, antiviruses, monitoring etc. My local host in the "/etc/hosts" was commented.

I solved this issue, but it was only an adb connection problem.

  • First, you have to enable all features in a device's developer menu (debug with USB, upload via USB, usb connection type - charge only), security menu (allow unknown sources);
  • Second, you have to set an allowance on the device to accept commands from a current PC. Some devices do not show a dialog. To force this, open a terminal console in the Android Studio, type in a command "adb logcat" (this push adb to connect with current device), you should see a dialog on the device's screen. Choose "Allow". To exit from logcat command, press ctrl+x/ctrl+c or ctrl+break;
  • After this, you should see the device in the Studio's logcat drop box as [disconnected];
  • Open the consloe again and type "adb wait-for-device", this should set a stable connection with device.

It helped me.

Sergio
  • 558
  • 5
  • 10
  • Not a hundred% solution. Adb has a lot of surprizes and often show multiple messages "can't start daemon", "error error". "adb devices" maybe helpfull to listen for a connected devices, "adb kill-server" + "adb start-server" to restart. Also you may disconnect device from the PC, close Android Studio, open a system task manager and kill the ADB process. Good luck) – Sergio Sep 27 '18 at 07:23
  • The other important thing: you may have several adb servers started at once. Uninstall/remove/backup wrong versions and add to the system environment path to the "../Android/sdk/platform-tools" https://stackoverflow.com/questions/43050370/adb-server-version-36-doesnt-match-this-client-39/43080159 – Sergio Sep 27 '18 at 08:39
  • It's stoped working again. New solution: i've changed the default ADB server port 5037 (Win10). In the "environment variables" add a variable "ANDROID_ADB_SERVER_PORT=5038" (where 5038 some free port). Uncomment localhost in the "../etc/hosts" anyway, this is the point :(. Apply changes with a windows relogin. – Sergio Sep 28 '18 at 10:23
0

I had a similar issue with Android Studio 3.3.1 (MacOS) when I run my app, it could not detect any devices in the Select Deployment Target dialog window after initializing adb. It produced the following error:

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

I checked in /etc/hosts, and found the following line: 10.0.2.2 localhost

Commenting out that line solved the issue.

borort
  • 65
  • 3
  • 9
0

In windows 10 I to need add path of ADB directory to environment PATH. And It helps.

user1575120
  • 301
  • 2
  • 4
0

The problem can be due to the fact that it is missing the adb driver for the specific phone, as you can verify from the device manager. You have to donwload and install it from the manufacturer, if it is available.

In my case, this seems to be still an open issue, but I've finally found the correct driver and installed it, as suggested in the developer documentation, by following the appropriate links (in my case I landed in a xiaomi Chinese page, containing the link to the rar archive of the working driver).

Having done that first, I could finally see an unauthorized device from adb devices (before that, no device was found instead, since it was unrecognized at the operating system level in the device manager) and, eventually, the suggestion from Sergio, typing adb logcat in the terminal, finally prompted the authorization from the device.

Issue solved!

-1

Check if the port is binded to any other connection in your computer. This may be the error which is caused de to ports inavailability. This Error ConnectException is caused due to SocketException so i will start digging with the port's status.

K. Dumre
  • 17
  • 8