Files
workphone-sdk/sdk/docs/docker_adb_tcpip.sh

37 lines
1.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# 让 Docker 内的 workphone-sdk 能通过「网络 ADB」发现手机解决 Hub 上 ADB=0
#
# 前提:
# 1) 手机与 Mac 在同一 WiFi且已获取 IPwlan0 有 inet
# 2) USB 仍插着,先在宿主机执行本脚本
# 3) 已 docker compose build && up且 compose 已挂载 ~/.android 到容器 /root/.android
#
# 用法bash sdk/docs/docker_adb_tcpip.sh [设备序列号]
set -euo pipefail
SERIAL="${1:-$(adb devices | awk '/\tdevice$/{print $1; exit}')}"
CTR="${DOCKER_CONTAINER:-workphone-sdk}"
if [[ -z "$SERIAL" ]]; then
echo "未检测到 USB 已授权设备"
exit 1
fi
IP="$(adb -s "$SERIAL" shell "ifconfig wlan0 2>/dev/null | awk '/inet addr/{print \$2}' | cut -d: -f2" | tr -d '\r')"
if [[ -z "$IP" ]]; then
IP="$(adb -s "$SERIAL" shell "ip -f inet addr show wlan0 2>/dev/null | awk '/inet /{print \$2}' | cut -d/ -f1" | tr -d '\r')"
fi
if [[ -z "$IP" ]]; then
echo "手机 wlan0 无 IP请先连接 WiFi与 Mac 同网段),再重试。"
exit 1
fi
echo ">>> USB 序列号: $SERIAL WiFi IP: $IP"
adb -s "$SERIAL" tcpip 5555
sleep 1
docker exec "$CTR" adb kill-server 2>/dev/null || true
docker exec "$CTR" adb connect "${IP}:5555"
docker exec "$CTR" adb devices -l
echo ""
echo ">>> 请刷新 Hub若仍为空执行: curl -s http://127.0.0.1:8899/api/v3/adb/scan"