未分类 · 2023年3月3日 0

Android 11 无线调试

内容纲要

首先手机电脑要处于同一局域网,然后手机上打开无线调试,第一次连接需要配对,之后可以直接 adb connect ip:port

在开发者设置无线调试中 点击 使用配对码配对设备

电脑运行下面命令,根据提示输入配对码,即可成功配对,同一个wifi下仅需配对一次

adb pair ip:port #这里是点击配对码配对后手机弹出的ip和端口

然后电脑运行下面命令

adb mdns services

输出:

List of discovered mdns services
adb-d0f1c6d6-Sq6jK8     _adb-tls-connect._tcp   192.168.1.156:40291

再运行:

#这个ip和端口就是上面输出的内容,也是手机无线调试界面显示的ip:port。与配对界面的ip:port不一样
adb connect 192.168.1.156:40291

如果要一键连接所有设备:

Windows powershell:

adb mdns services | Select-String -Pattern '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+' | ForEach-Object {adb connect $($_.Matches.Value)}

MacOS、Linux:

adb mdns services | grep -Eo '\b([0-9]{1,3}\.){3}[0-9]{1,3}:[0-9]+' | awk '{print "adb connect "$1}'
此命令将执行以下操作:

运行 adb mdns services 命令并将其输出传递给管道符号 |。
将输出传递给 Select-String 命令,并使用正则表达式模式 \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+ 查找包含 IP 地址和端口号的行。
将匹配的行传递给 ForEach-Object 命令,并使用 $_.Matches.Value 提取 IP 地址和端口号。
将 IP 地址和端口号传递给 adb connect 命令。

每次打开无线调试太麻烦?我写了一个好工具:https://github.com/wilinz/Devtools 下载release中的APK安装即可