连接方法
方法很简单,具体步骤如下:
1.先确保你手机和电脑运行在同一wifi局域网内
2.由于是通过adb来进行连接的,所以确保你配置了环境变量
3.第一次的时候需要用手机USB连接到你的电脑,之后运行下面国外大牛写的shell脚本连接成功就可以把你的USB数据线拔掉了,然后你的电脑就可以通过wifi调试你的应用了。
Linux:
#!/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
Windows:
@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