https://learn.microsoft.com/zh-cn/windows/wsl/wsl-config
https://learn.microsoft.com/zh-cn/windows/wsl/connect-usb
https://github.com/dorssel/usbipd-win
https://github.com/dorssel/usbipd-win/wiki/WSL-suppor
1. 安装usbipd: winget install usbipd
2. 以管理员模式打开 PowerShell
3. 连接usb设备后
usbipd list
Connected:
BUSID VID:PID DEVICE STATE
2-1 046d:c52b Logitech USB Input Device, USB 输入设备 Not shared
2-2 22d9:2765 OnePlus 8T, ADB Interface Shared (forced)
2-7 3277:0004 Integrated Webcam_FHD Not shared
2-10 8087:0033 英特尔(R) 无线 Bluetooth(R) Not shared
VID: 厂商号
PID: 产品号
4. usbipd bind --busid 2-2 --force
5. usbipd attach --wsl --busid 2-2
usbipd: info: Using WSL distribution 'Ubuntu-22.04' to attach; the device will be available in all WSL 2 distributions.
usbipd: info: Detected networking mode 'nat'.
usbipd: info: Using IP address 172.23.0.1 to reach the host.
打开WSL2下的Linux系统,以Ubuntu为例
6. lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 22d9:2765 OPPO Electronics Corp. Oppo N1
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
7. sudo vim /etc/udev/rules.d/51-android.rules
SUBSYSTEM=="usb", ATTR{idVendor}=="22d9", ATTR{idProduct}=="2765", MODE="0666"
8. 重新插拔USB设备,重新执行5后
adb devices
List of devices attached
d3f363ba unauthorized
9. 打开USB设备,勾选授权允许连接后,再次执行8
adb devices
List of devices attached
d3f363ba device
10. 打开Android Studio,就可以在设备列表看到USB设备了,可以进行APP的调试了。
usbipd detach --busid 2-2
sudo apt install java-common
sudo update-java-alternatives --list
sudo update-alternatives --config java