问题描述
Windows下安装Android studio,里面含有Android SDK,自动包含了adb在内的很多工具包;因开发需要,在WSL中安装了Ubuntu,分别是18和22的,其中也分别安装了Android SDK,官网下载,可以运行adb命令。
本来在Windows下和Ubuntu下都可以直接使用,但是今天上来在Ubuntu下突然找不到设备了,运行adb devices,显示:
shell
List of devices attached
adb server version (41) doesn't match this client (39); killing...
* daemon started successfully
再次运行命令,依旧是空列表:
shell
List of devices attached
问题原因
执行一些简单操作:
shell
adb kill-server
adb start-server
* daemon not running; starting now at tcp:5037
* daemon started successfully
依旧找不到:
shell
List of devices attached
在Windows下试一下:
shell
adb server version (39) doesn't match this client (41); killing...
* daemon started successfully
List of devices attached
c731111d device
发现虽然也有不匹配的问题,但是是可以找到设备的。
有趣的是,这2个地方adb server,adb client的相反的,逛了一下Stackoverflow,可能是版本的问题。在Windows下和Ubuntu下的adb版本不同。
问题解决
Windows下运行:
shell
C:\Users\xxx\AppData\Local\Android\Sdk\platform-tools\adb --version
显示:
shell
Android Debug Bridge version 1.0.41
Version 34.0.4-10411341
Installed as C:\Users\xxx\AppData\Local\Android\Sdk\platform-tools\adb.exe
Running on Windows 10.0.18363
Ubuntu下运行:
shell
adb --version
显示:
shell
Android Debug Bridge version 1.0.39
Version 1:8.1.0+r23-5~18.04
Installed as /usr/lib/android-sdk/platform-tools/adb
先把Windows的让他不起作用(重命名或者移出环境),在Ubuntu下接着尝试,发现
shell
$ adb start-server
adb server version (41) doesn't match this client (39); killing...
ADB server didn't ACK
Full server startup log: /tmp/adb.1000.log
Server had pid: 16935
--- adb starting (pid 16935) ---
adb I 09-21 14:38:17 16935 16935 main.cpp:57] Android Debug Bridge version 1.0.39
adb I 09-21 14:38:17 16935 16935 main.cpp:57] Version 1:8.1.0+r23-5~18.04
adb I 09-21 14:38:17 16935 16935 main.cpp:57] Installed as /usr/lib/android-sdk/platform-tools/adb
adb I 09-21 14:38:17 16935 16935 main.cpp:57]
adb I 09-21 14:38:17 16935 16935 adb_auth_host.cpp:416] adb_auth_init...
adb I 09-21 14:38:17 16935 16935 adb_auth_host.cpp:174] read_key_file '/home/xxx/.android/adbkey'...
adb I 09-21 14:38:17 16935 16935 adb_auth_host.cpp:391] adb_auth_inotify_init...
adb server killed by remote request
* failed to start daemon
error: cannot connect to daemon
没有启动成功,而这里报的错误是adb所在路径并不是我们所安装的路径【那是什么时候安装的呢?】,我们所安装的只有在自己当时下载解压的位置,检查版本:
shell
~/tools/platform-tools/adb --version
结果:
shell
Android Debug Bridge version 1.0.41
Version 34.0.4-10411341
Installed as /home/gy/tools/platform-tools/adb
Running on Linux 4.4.0-18362-Microsoft (x86_64)
这个才是我们需要的,版本也是正确的