Android通过Wifi来调试

本文详细介绍了使用adb命令将手机连接至电脑,从而实现无线调试的方法。包括确保设备处于同一局域网、配置环境变量及使用特定脚本进行连接。此教程适用于Linux和Windows操作系统。

连接方法

方法很简单,具体步骤如下:

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


转载于:https://my.oschina.net/Moy/blog/424524

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值