1. 问题描述
Error initializing ADB: Unable to create Debug Bridge: Unable to start adb server:* daemon not running; starting now at tcp:5037 could not read ok from ADB Server * failed to start daemon error: cannot connect to daemon 'D:\AndroidSDK\platform-tools\adb.exe start-server’failed–run manually if necessary
C:\Users\iqqcode>adb shell * daemon not running. starting it now on port 5037 * error: could not install *smartsocket* listener: cannot bind to 127.0.0.1:5037: 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。 (10048) could not read ok from ADB Server * failed to start daemon * error: cannot connect to daemon
* daemon not running; starting now at tcp:5037 could not read ok from ADB Server * failed to start daemon error: cannot connect to daemon
2. 问题原因及解决
2.1 原因一:adb的5037端口被占
情况一:端口被固定过程占用
首先,在CMD下面,找到占用端口的过程PID
netstat -ano | findstr 5037 | findstr LISTENING TCP 127.0.0.1:5037 0.0.0.0:0 LISTENING 17024
通过这个PID,找到占用程序
tasklist /FI "PID eq 17024" 映像名称 PID 会话名 会话# 内存使用 ========================= ======== ================ =========== ============ adb.exe 17024 Console 1 8,788 K
tasklist是Win在本地或远程计算机上显示所有操作过程的命令,/FI 显示一系列符合筛选器指定的过程。
通过程序名找到路径
wmic process where name="adb.exe" get executablepath ExecutablePath C:\Androd\sdk\platform-tools\adb.exe
taskkill /F /PID 17024
坑爹的情况二:被固不定的某一进程占用端口
占用的进程PID不固定,也不知道是哪个程序导致的(找了很久,我直接暴风哭泣,它一直在变;用上面杀掉该进程,还是不太行)
上面情况一的方法其实是治标不治本,我们还是尽量换一个adb的端口吧
adb分配固定关口
Windows11 配置环境变量的入口有所改变
- 变量名:
ANDROID_ADB_SERVER_PORT
- 值:
11223
- win下,在cmd输入:
set ANDROID_ADB_SERVER_PORT=54321
- linux下,输入:
export ANDROID_ADB_SERVER_PORT=54321
2.2 原因二:platform-tools文件有问题
先重装开发包工具,下载并且替换为新下载文件
SDK Platform Tools 版本说明下载: https://developer.android.com/studio/releases/platform-tools#tos-header
删了换为下载后的新内容
再按照以下步骤操作即可。
:- 关闭 Android-Studio。 :- 打开命令提示符或win+ r,键入cmd并按Enter。 :- 导航到platform-tools文件夹下,在大多数情况下,位置是:
C:\Users\[user]\AppData\Local\Android\android-sdk\platform-tools
对于 Mac 用户,路径是
/Users/[user]/Library/Android/sdk/platform-tools
:- 键入adb.exe start-server,按Enter :- 再次打开 Android Studio。
对于 Mac,命令只是 adb start-server
问题应该得到解决!
参考自:Stack Overflow - error-initializing-adb-unable-to-create-debug-bridge-unable-to-start-adb-serve