使用WSL跑测CTS注意事项

## **使用WSL跑测CTS注意事项**

推荐使用WSL1,因为WSL2上adb识别不到机器。

####

首先安装WSL2.然后,

#### **将版本从 WSL 2 降级到 WSL 1**

版本的相互转换也不复杂:

转换之前先检查当前版本:

 

```
wsl -l -v
```

 

 

 

然后更改指定发行版的版本:

 

```
wsl --set-version <发行版> <版本>
```

 

 

 

例:

 

**切换之前:**

 

windows命令行下:

先查询当前系统和版本

 

```
D:\>wsl -l -v
NAME STATE VERSION
* Ubuntu Running 2

adb可以识别设备
D:\>adb kill-server
D:\>adb devices
* daemon not running; starting now at tcp:5037
* daemon started successfully
List of devices attached
eae2609d device
```

 

 

 

 

WSL命令行下:

 

```
d@xx:~$ adb --version
Android Debug Bridge version 1.0.41
Version 35.0.1-11580240
Installed as /home/d//Android/Sdk/platform-tools/adb
Running on Linux 5.15.133.1-microsoft-standard-WSL2 (x86_64)

adb不识别设备
d@xx:~$ adb devices
* daemon not running; starting now at tcp:5037
* daemon started successfully
List of devices attached
```

 

 

 

**设置为WSL1**

 

windows命令行下

 

```
D:\>wsl --set-version ubuntu 1
正在进行转换,这可能需要几分钟时间。
操作成功完成。

D:\>wsl -l -v
NAME STATE VERSION
* Ubuntu Running 1
```

 

 

WSL命令行下:

 

```
d@xx:~$ adb --version
Android Debug Bridge version 1.0.41
Version 35.0.1-11580240
Installed as /home/d//Android/Sdk/platform-tools/adb
Running on Linux 4.4.0-19041-Microsoft (x86_64)
```

 

 

 

 

```
D:\>adb devices
List of devices attached
eae2609d device
```

 

 

 

WSL命令行下:

 

```
d@xx:~$ adb devices
List of devices attached
eae2609d device
```

 

**如果使用WSL1, adb无法识别机器,可以尝试如下方法:**

\# windows下

```
adb kill-server

adb devices // 这一步启动adb server,发现设备
```

 

\# ubuntu下

```
adb devices
```

如果还不行,请确保windows 系统的adb version 必须与linux 子系统的adb version保持一致

#### **windows 系统的adb version 必须与linux 子系统的adb version保持一致**

原因:

[@sunjoong](https://github.com/sunjoong) [timcanham (Timothy Canham) · GitHub](https://github.com/timcanham)

Please do read what I posted carefully [ethanhs/WSL-Programs#29 (comment)](https://github.com/ethanhs/WSL-Programs/issues/29#issue-170066892)

ADB is functional **only when you start adb server in the host system(windows)**, thus host system would handle all usb traffic for bash on windows.

That's also why **adb on both sides are required to be the very same version** so they would recognize each other and communicate through tcp.

It's not natively supported by bash because usb is not generally working on bash.

In addition I assume adb over tcp/ip (adb connect [IP]) would work even with adb server started in bash.

I test it in my PC, **the version of adb in bash should be same as it in cmd**, because if the version of adb client not match the version of adb server, the adb server will be killed by adb client in bash and restart adb server in bash, adb server in bash can't access the devices in windows. so there are steps to make sure adb work in bash:

​ \1. there are same version of adb in bash and cmd.

​ \2. start adb-server in cmd first, and make sure adb-server running in windows end.

[USB device support, libusb (ADB support, etc) · Issue #2195 · microsoft/WSL · GitHub](https://github.com/microsoft/WSL/issues/2195)

https://github.com/microsoft/WSL/issues/2195)

 

参考链接:

安装 WSL | Microsoft Learn

posted @ 2025-05-21 09:57  lazyy  Views(95)  Comments(0)    收藏  举报