Android_ADB_通过WIFI或USB方式完成调试


参考:

http://blog.csdn.net/zimo2013/article/details/39552129?utm_source=tuicool&utm_medium=referral

 

1. 用usb线将手机和PC连接起来

2. 然后在手机端执行

adb root 然后使用adb shell登陆手机, 执行如下命令: setprop service.adb.tcp.port 5555 stop adbd &&  start adbd &

3. 然后在PC端执行

adb tcpip 5555 adb connect 192.168.*.* (手机ip):5555 (如果还连着USB, 输入其他命令时先输入adb devices, 输入adb -s device_name 命令) 用下面的命令切回到usb方式 adb usb

4. 此时拔掉USB线, 使用adb shell命令,发现还可以登陆手机

为了省事,可以将上面的操作放到一个脚本中:

#!/bin/bash if [ "x$1" == "xf" ];then # 有时在wifi断了后, 又重新连上了,可以直接使用./wifi.sh f phone_ip=`cat /tmp/phone_ip.1234` if [ "x$phone_ip" != "x" ];then
        echo "connect to $phone_ip" adb -s $phone_ip connect $phone_ip fi exit 0
fi devices=`adb devices | grep "\<device\>" | awk '{print $1}'` count=0
for i in $devices do let count++
done

if [ $count -gt 1 ];then
select device in $devices; do break; done
elif [ $count -eq 0 ];then device=""
else device=$devices fi

if [ "x$device" == "x" ];then
    echo "device: $device not exist" exit -1
fi port=`adb -s $device wait-for-device && adb -s $device shell "getprop service.adb.tcp.port"` if [ "x$port" != "x5555" ];then adb -s $device wait-for-device && adb -s $device root adb -s $device wait-for-device && adb -s $device shell "setprop service.adb.tcp.port 5555" adb -s $device wait-for-device && adb -s $device shell "stop adbd && start adbd &" adb -s $device wait-for-device && adb -s $device tcpip 5555
sleep 1
fi tmp=`adb -s $device wait-for-device && adb -s $device shell ifconfig |  grep "172.16" | awk -F ':' '{print $2}' | awk '{print $1}'` if [ "x$tmp" == "x" ];then
    echo "ip is none" exit -1
fi
echo "connect to $tmp"
echo "$tmp:5555" > /tmp/phone_ip.1234 adb -s $tmp:5555 connect $tmp

 

对于不能root的手机也可以:

1、 确保电脑和Android设备连接在同一个WIFI网络环境。

2、 用USB线连接Android设备。连接上之后你的电脑就会检查到设备并且ADB将会以USB模式启动。可以通过adb devices命令检查连接上的设备,用adb usb命令确认adb是运行在usb模式下面。

1 $ adb devices 2 List of devices attached 3 04bdc4c9252391b9 device 4 
5 $ adb usb 6 restarting in USB mode

3、用adb tcpip模式重启adb

1 $ adb tcpip 5555
2 restarting in TCP mode port: 5555

4、 查看Android设备的IP地址,这里有三种方式查看Android设备IP。

  • 设置-关于手机-状态信息-ip地址中查看

  • 设置-WLAN-点击当前链接上的Wi-Fi查看IP

  • 通过ADB命令查看设备IP地址:adb shell netcfg 或者 adb shell ifconfig

5、知道设备IP地址之后,就可以用adb connect命令通过IP和端口号连接ADB了。

1 $ adb connect 192.168.1.3:5555
2 connected to 192.168.1.3:5555
3 
4 #查看一下连接上的设备,usb连接和wifi连接都存在 5 adb devices 6 List of devices attached 7 04bdc4c9252391b9 device 8 192.168.1.3:5555 device

拔掉USB线,你会发现设备仍然是连接上的,如果没有连接上,用刚才的命令重现尝试一下。

 

完.


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM