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

来源:互联网 发布:萧山网络问政进化镇 编辑:程序博客网 时间:2024/05/15 11:40

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

2. 然后在手机端执行

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

3. 然后在PC端执行

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

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

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

复制代码
#!/bin/bashif [ "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 0fidevices=`adb devices | grep "\<device\>" | awk '{print $1}'`count=0for i in $devicesdo    let count++doneif [ $count -gt 1 ];thenselect device in $devices;do    break;doneelif [ $count -eq 0 ];then    device=""else    device=$devicesfiif [ "x$device" == "x" ];then    echo "device: $device not exist"    exit -1fiport=`adb -s $device wait-for-device && adb -s $device shell "getprop service.adb.tcp.port"`if [ "x$port" != "x5555" ];thenadb -s $device wait-for-device && adb -s $device rootadb -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 5555sleep 1fitmp=`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 -1fiecho "connect to $tmp"echo "$tmp:5555" > /tmp/phone_ip.1234adb -s $tmp:5555 connect $tmp
复制代码

 

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

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

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

复制代码
1 $ adb devices2 List of devices attached3 04bdc4c9252391b9 device4 5 $ adb usb6 restarting in USB mode
复制代码

3、用adb tcpip模式重启adb

1 $ adb tcpip 55552 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:55552 connected to 192.168.1.3:55553 4 #查看一下连接上的设备,usb连接和wifi连接都存在5 adb devices6 List of devices attached7 04bdc4c9252391b9 device8 192.168.1.3:5555 device
复制代码
拔掉USB线,你会发现设备仍然是连接上的,如果没有连接上,用刚才的命令重现尝试一下
原创粉丝点击