adbwindows-11

Can't use ADB at all


I have very weird problems with ADB which I can't start or kill ADB server at all.

This is what I get when I try to use adb start-server (with set ADB_TRACE=all)

E:\DOWNLOAD\platform-tools>adb start-server
adb D 07-09 16:41:13  9808  9160 adb_trace.cpp:187] Android Debug Bridge version 1.0.41
adb D 07-09 16:41:13  9808  9160 adb_trace.cpp:187] Version 34.0.3-10161052
adb D 07-09 16:41:13  9808  9160 adb_trace.cpp:187] Installed as E:\DOWNLOAD\platform-tools\adb.exe
adb D 07-09 16:41:13  9808  9160 adb_trace.cpp:187] Running on Windows 10.0.22621
adb D 07-09 16:41:13  9808  9160 adb_trace.cpp:187]
adb D 07-09 16:41:13  9808  9160 adb_client.cpp:351] adb_connect: service: host:start-server
adb D 07-09 16:41:13  9808  9160 adb_client.cpp:160] _adb_connect: host:version
adb D 07-09 16:41:15  9808  9160 sysdeps_win32.cpp:1032] could not connect to tcp:5037: cannot connect to 127.0.0.1:5037: 대상 컴퓨터에서 연결을 거부했으므로 연결하지 못했습니다. (10061)
adb D 07-09 16:41:15  9808  9160 sysdeps_win32.cpp:602] _socket_set_errno: mapping Windows error code 10061 to errno 22
* daemon not running; starting now at tcp:5037
adb D 07-09 16:41:15 12680  8312 adb_trace.cpp:187] Android Debug Bridge version 1.0.41
adb D 07-09 16:41:15 12680  8312 adb_trace.cpp:187] Version 34.0.3-10161052
adb D 07-09 16:41:15 12680  8312 adb_trace.cpp:187] Installed as E:\DOWNLOAD\platform-tools\adb.exe
adb D 07-09 16:41:15 12680  8312 adb_trace.cpp:187] Running on Windows 10.0.22621
adb D 07-09 16:41:15 12680  8312 adb_trace.cpp:187]
could not read ok from ADB Server
* failed to start daemon
adb D 07-09 16:41:17  9808  9160 sysdeps_win32.cpp:151] _fh_from_int: invalid fd -2 passed to adb_close
error: cannot connect to daemon

Common workaround is executing adb kill-server. This is what I get when I execute it.

E:\DOWNLOAD\platform-tools>adb kill-server
adb D 07-09 16:41:42  2500  2188 adb_trace.cpp:187] Android Debug Bridge version 1.0.41
adb D 07-09 16:41:42  2500  2188 adb_trace.cpp:187] Version 34.0.3-10161052
adb D 07-09 16:41:42  2500  2188 adb_trace.cpp:187] Installed as E:\DOWNLOAD\platform-tools\adb.exe
adb D 07-09 16:41:42  2500  2188 adb_trace.cpp:187] Running on Windows 10.0.22621
adb D 07-09 16:41:42  2500  2188 adb_trace.cpp:187]
adb D 07-09 16:41:42  2500  2188 adb_client.cpp:199] adb_kill_server
adb D 07-09 16:41:44  2500  2188 sysdeps_win32.cpp:1032] could not connect to tcp:5037: cannot connect to 127.0.0.1:5037: 대상 컴퓨터에서 연결을 거부했으므로 연결하지 못했습니다. (10061)
adb D 07-09 16:41:44  2500  2188 sysdeps_win32.cpp:602] _socket_set_errno: mapping Windows error code 10061 to errno 22
cannot connect to daemon at tcp:5037: cannot connect to 127.0.0.1:5037: 대상 컴퓨터에서 연결을 거부했으므로 연결하지 못 했습니다. (10061)

It seems something is using tcp:5037.

But I don't see any program occupying TCP port 5037. Nothing is printed when I run netstat -aon | findstr 5037, tasklist | findstr 5037 and tasklist | findstr adb even with Administrator privilege. I even tried NMAP but still I don't see any program using that port.

So I tried to use another port with adb. I tried adb -P 12345 start-server.

E:\DOWNLOAD\platform-tools>adb -P 12345 start-server
adb D 07-09 16:48:17 13240  8404 adb_trace.cpp:187] Android Debug Bridge version 1.0.41
adb D 07-09 16:48:17 13240  8404 adb_trace.cpp:187] Version 34.0.3-10161052
adb D 07-09 16:48:17 13240  8404 adb_trace.cpp:187] Installed as E:\DOWNLOAD\platform-tools\adb.exe
adb D 07-09 16:48:17 13240  8404 adb_trace.cpp:187] Running on Windows 10.0.22621
adb D 07-09 16:48:17 13240  8404 adb_trace.cpp:187]
adb D 07-09 16:48:17 13240  8404 adb_client.cpp:351] adb_connect: service: host:start-server
adb D 07-09 16:48:17 13240  8404 adb_client.cpp:160] _adb_connect: host:version
adb D 07-09 16:48:19 13240  8404 sysdeps_win32.cpp:1032] could not connect to tcp:12345: cannot connect to 127.0.0.1:12345: 대상 컴퓨터에서 연결을 거부했으므로 연결하지 못했습니다. (10061)
adb D 07-09 16:48:19 13240  8404 sysdeps_win32.cpp:602] _socket_set_errno: mapping Windows error code 10061 to errno 22
* daemon not running; starting now at tcp:12345
adb D 07-09 16:48:19 10032 10072 adb_trace.cpp:187] Android Debug Bridge version 1.0.41
adb D 07-09 16:48:19 10032 10072 adb_trace.cpp:187] Version 34.0.3-10161052
adb D 07-09 16:48:19 10032 10072 adb_trace.cpp:187] Installed as E:\DOWNLOAD\platform-tools\adb.exe
adb D 07-09 16:48:19 10032 10072 adb_trace.cpp:187] Running on Windows 10.0.22621
adb D 07-09 16:48:19 10032 10072 adb_trace.cpp:187]
could not read ok from ADB Server
* failed to start daemon
adb D 07-09 16:48:20 13240  8404 sysdeps_win32.cpp:151] _fh_from_int: invalid fd -2 passed to adb_close
error: cannot connect to daemon

Same error happened.

These are what else I've tried:

I really don't know what to do else. Even Google couldn't help me for this strange behavior.

Re-installing Windows would be final choice, but I doubt it would help because I've experiencing this issue even before re-installing Windows few weeks ago.


Solution

  • I can't believe that I couldn't use ADB for this...

    I symlinked %UserProfile%\.android directory to other drive before. Let's say that the destination directory is E:\.android.

    At the time when I was trying to use adb, E:\.android directory was not present. Since %UserProfile%\.android was still present (but with non-existent destination), ADB couldn't create new .android directory. This prevented ADB to create new adbkey and adbkey.pub file.

    Since ADB couldn't create required files, it failed to process start-server. And since there was no running ADB server, kill-server also failed.

    I created E:\.android and ADB runs without any problem.

    This is weird because ADB recognized my device as offline(very old version of ADB) and unauthorized(old version of ADB), but not in latest version of ADB.


    TL;DR

    Check if %UserProfile%\.android is valid directory and accessible.