24

I've been using AS for months, but since two days I get an error when I try to run my app:

Unable to run 'adb': null
'C:\Users\lapof\AppData\Local\Android\Sdk\platform-tools\adb.exe start-server' failed -- run manually if necessary
* daemon not running; starting now at tcp:5037
could not read ok from ADB Server
* failed to start daemon
error: cannot connect to daemon

I've read about a lot of people having this problem, but the solutions provided don't work for me. I read these questions in particular:

A lot of answers to these questions say to close adb.exe from task manager, the problem is that adb.exe is not running and if I try to restart it by typing .\adb start-server on a PowerShell window I get the same error.

I also try to restart my PC but it didn't work. On the Android device I'm trying to connect to (Samsung Galaxy S8) I enabled USB debugging. I even tried to eliminate all the authorized devices, but nothing worked.

I checked if the 5037 port was used by other processes, but it is used by adb.exe (and the firewall state on that port is allowed and not limited). By the way, as I said, in the task manager adb.exe is not present.

Last I tried to follow the instructions provided in the last question I linked (basically I re-downloaded adb.exe). Initially I ran .\adb start-server and this strange error occurs:

* daemon not running. starting it now on port 5037 *
* daemon started successfully *
** daemon still not running
error: cannot connect to daemon

and then when I try to run my app on Android Studio it occurs this new error when it tries to start adb:

Unable to run 'adb': null
'C:\Users\lapof\AppData\Local\Android\Sdk\platform-tools\adb.exe start-server' failed -- run manually if necessary
ADB server didn't ACK
* failed to start daemon *

and then if I try to .\adb kill-server and then .\adb start-server or .\adb devices or .\adb usb the same error occurs again. Moreover when I connect my device now it asks me to authorize my PC to connect.

I don't know if this can help, but lately I deactivated a lot of Windows services (but I don't think I deactivated something related to Android Studio).


Details

  • PC: Compaq
  • PC OS: Windows 10 Home
  • Device: Samsung Galaxy S8 (Exynos)
  • Device OS: Android 8.0
  • AS version: 3.0.1
Lapo
  • 882
  • 1
  • 12
  • 28
  • have you authorized USB debugging ?? – Martin Zeitler Sep 04 '18 at 20:48
  • @MartinZeitler yes – Lapo Sep 04 '18 at 20:49
  • I'd suspect it to already run, possibly due to having Genemotion installed `stop-server` & `start-server` ordinary helps; also make sure no local firewall is blocking the default port `tcp:5555`. – Martin Zeitler Sep 04 '18 at 20:54
  • `Start > All Programs > Accessories > System Tools > Resource Monitor > Network > Listening Ports` can be used to see if the port is already in used by any other application. – Martin Zeitler Sep 04 '18 at 20:56
  • @MartinZeitler I don't use Genymotion (my old PC doesn't support emulators :( ). Why is port 5555 important? Isn't adb using 5037? – Lapo Sep 04 '18 at 20:56
  • @MartinZeitler Yes, I used that exact same path to find out that 5037 port is used by adb.exe. Port 5555 is not in that list tho. Thanks – Lapo Sep 04 '18 at 20:57
  • https://developer.android.com/studio/command-line/adb#howadbworks ...it's always a pair of ports, 1 per adb device and 1 per adb server ...eg. two hardware devices would require 4 ports (no matter if automatically assigned or explicitly passed). – Martin Zeitler Sep 04 '18 at 21:00
  • @MartinZeitler ok thanks, btw port 5555 is not in the list of Listened Ports. Is this an issue? – Lapo Sep 04 '18 at 21:04

15 Answers15

21

Usually that's caused by the WinNAT service, restarting which solves the issue.

Just open the Command Prompt or PowerShell as Administrator, and type the following commands there:

net stop winnat
net start winnat

And wait a bit for the Android Studio to reconnect to the ADB.

P.S. If it doesn't reconnect, just type the following commands to restart the ADB:

adb kill-server
adb start-server
Just Shadow
  • 10,860
  • 6
  • 57
  • 75
15

The solution which worked for me -

Open Command Prompt as administrator and type

adb start-server

That's it

Payel Senapati
  • 1,134
  • 1
  • 11
  • 27
13

I had same problem a moment ago. I solved it:

Run CMD as Administrator

Enter adb devices to CMD.

The output for me is :

C:\WINDOWS\system32>adb devices
List of devices attached
* daemon not running; starting now at tcp:5037
* daemon started successfully
P9BCS87ABS9SCD5 device
canmustu
  • 2,304
  • 4
  • 21
  • 34
  • 2
    'adb' is not recognized as an internal or external command, operable program or batch file. How to deal this – Kusumakar Pant Jul 09 '19 at 21:51
  • @KusumakarPant Either you add adb to the path or you use the full path – yoel halb Oct 11 '19 at 16:00
  • Thanks, this solved it, note that as soon as the daemon is started it will already work even from a non admin console – yoel halb Oct 11 '19 at 16:01
  • that was an interesting trick ;) mine was version doesn't match error. It killed and started after this command – Prabs Nov 13 '19 at 07:09
  • i got this error when running above command, can you help? * daemon not running; starting now at tcp:5037 could not read ok from ADB Server * failed to start daemon adb.exe: failed to check server version: cannot connect to daemon – Sandy Rizky Sep 12 '21 at 13:09
5

I solved the problem on my own.

Out of frustration I opened Control Panel > System and security > Windows defender firewall > Allowed applications and I added adb.exe (both private and public networks).

I came back to Android Studio, ran the app and magically it managed to initialize ADB and my phone connected via USB was there.

I don't really know why this worked, since when I checked in Start > All Programs > Accessories > System Tools > Resource Monitor > Network > Listening Port it said that on port 5037 the firewall was allowed.

Moreover I don't know why up to a week ago all worked fine and now I had to do this process to make it work.

If someone more experienced manages to explain this behaviour better I'll update this answer (or accepts his as best answer)

Lapo
  • 882
  • 1
  • 12
  • 28
5

Run CMD or PowerShell as administrator

Then run the following commands:

net stop winnat

In correct folder run:

adb start-server
net stop winnat
Maetschl
  • 1,330
  • 14
  • 23
5

Below solution solved my problem:

  1. Go to your task manager
  2. see if adb is running
  3. right click & end the task
  4. Go to command prompt
  5. run adb devices

it will work fine

Jonathan
  • 1,955
  • 5
  • 30
  • 50
HemanthSDET
  • 51
  • 1
  • 1
3

For my situation The latest platform is version 30.0.3. I also have the same problem as this:

* daemon not running. starting it now on port 5037 *
* daemon started successfully * 

My solving:

2
  1. SDK Manager -> SDK tools
  2. Uncheck "Android SDK Platform - Tool"
  3. Click Apply
2

After using Android Studio and Emulator without any problems, suddenly it stop to connect to the Emulator, even adb server was running (killing and starting), firewalls raised for all the programs (adb.exe, qemu-system-x86_64.exe, studio64.exe, etc), port 5037 freed, uninstalled and installed again the programs, even the whole Android Studio from scratch. I got verything running OK, but no connection between AS and Emulator.

The solution to my problem was to run Android Studio AS ADMINISTRATOR, it seems that when I updated the program to 3.5.2 somehow the status changed, causing me the problem.

Zoe
  • 27,060
  • 21
  • 118
  • 148
pvalle
  • 1,335
  • 1
  • 13
  • 20
  • 1
    When I got the problem over an year ago, I haven't tried this! Probably a very good solution. Luckily it hasn't happened to me again. – Lapo Dec 02 '19 at 22:18
1

What worked for me in all adb unresolved cases:

adb kill-server

or

adb disconnect

I would just try them both and one will do the trick.

Gogu CelMare
  • 699
  • 6
  • 15
0

I had this issue several times. It seems if when system is starting, device is connected by USB cable, daemon will connect correctly and no problem will occur. Of course I want a better solution, because it is very hard for me to shut down and start again every time.

MMG
  • 3,226
  • 5
  • 16
  • 43
0

Had same issue after upgrading to Android Studio Bumblebee | 2021.1.1

To solve it, go to Settings -> Build, Excecution, Deployment -> Debugger

Then uncheck the option Enable adb mDNS for wierless debugger

Ayman Al-Absi
  • 2,630
  • 24
  • 22
0

I had the same error.

Error on android studio

i use easytether, which was causing the error when is connected. http://www.mobile-stream.com/easytether/android_faq.html#adbmacosx

After u disconnect it, everything should work fine.

0

The symptom usually happens after enabling Hyper-V service, as Hyper-V reserves ports for internal usage [1], which could be verified by running netsh int ipv4 show dynamicport tcp.

After my machine (Windows 10 IoT LTSC, Build 19044.3086) having Hyper-V enabled, the output looks like this:

C:\Users\aster>netsh int ipv4 show dynamicport tcp

Protocol tcp Dynamic Port Range
---------------------------------
Start Port      : 1024
Number of Ports : 64511

The reserved port covers the one adb uses.

To solve the problem permanently, you need to set the reserved ports to a higher range[2], for example:

netsh int ipv4 set dynamic tcp start=49152 num=16384
netsh int ipv6 set dynamic tcp start=49152 num=16384

Remember to reboot your machine. This will move WinNAT reserved port range to 49152~65534, and is the true answer to this problem.

Reference:

  1. https://learn.microsoft.com/en-US/troubleshoot/windows-server/networking/default-dynamic-port-range-tcpip-chang

  2. https://github.com/docker/for-win/issues/3171

march_happy
  • 420
  • 5
  • 11
0

The only solution that worked for me on latest Windows 11 was to go with this command to start a dedicated server background process:

adb.exe nodaemon server

After that I could run any other adb-command as usual.

Carsten
  • 1,612
  • 14
  • 21