在平时的工作中,我们调试android工程一般都是通过调试线连上机器的,这样多多少少会限制到我们的开发测试,但是有了wifi调试后,我们就可以不用带着 android机器,调试线到处跑啦。现在来看看要怎么做,才能使用wifi调试android机器。
##前提条件
在执行下面操作前,要将USB调试线连接上电脑,确保在有线状态下能使用adb调试机器。
##手动方式实现WIFI的调试
adb shell ifconfig wlan0 //或者用adb shell netcfg
adb tcpip 5555
adb connect 192.168.X.X:5555
通过***adb shell ifconfig wlan0***得到机器的IP地址。然后adb connect执行的时候就可以使用这个IP地址连上机器,连上后,就可以拔掉usb调试线啦,然后尽情的在无线wifi的状态调试机器吧。
##脚本实现WiFi的调试
- ###linux环境
adbwifi.sh
#!/bin/bash
#Modify this with your IP range
MY_IP_RANGE="192\.168\.1"
#You usually wouldn't have to modify this
PORT_BASE=5555
#List the devices on the screen for your viewing pleasure
adb devices
echo
#Find USB devices only (no emulators, genymotion or connected devices
declare -a deviceArray=(`adb devices -l | grep -v emulator | grep -v vbox | grep -v "${MY_IP_RANGE}" | grep " device " | awk '{print $1}'`)
echo "found ${#deviceArray[@]} device(s)"
echo
for index in ${!deviceArray[*]}
do
echo "finding IP address for device ${deviceArray[index]}"
IP_ADDRESS=$(adb -s ${deviceArray[index]} shell ifconfig wlan0 | awk '{print $3}')
echo "IP address found : $IP_ADDRESS "
echo "Connecting..."
adb -s ${deviceArray[index]} tcpip $(($PORT_BASE + $index))
adb -s ${deviceArray[index]} connect "$IP_ADDRESS:$(($PORT_BASE + $index))"
echo
echo
done
adb devices -l
#exit
- ###window环境
adbwifi.bat
@echo off &setlocal enabledelayedexpansion
::set your port
set PORT_BASE=5555
::list the device
adb devices |findstr /i "\<device\>" >nul
if "%errorlevel%" neq "0" (
echo "device not found."
goto :eof
)
::set devices serial
for /f "tokens=1" %%i in ('adb devices^|findstr "\<device\>"') do (
set device_serial=%%i
echo
)
echo found devices %device_serial%
::find IP for the phone
for /f "tokens=3 delims= " %%i in ('adb shell ifconfig wlan0') do (
set phone_ip=%%i
)
echo device ip is %phone_ip%
echo "Connecting......"
adb -s %device_serial% tcpip %PORT_BASE%
adb -s %device_serial% connect %phone_ip%:%PORT_BASE%
echo Done
adb devices -l
ping -n 4 127.0.0.1 >&2 >nul
##参考文章
Android通过Wifi来调试你的应用