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线,你会发现设备仍然是连接上的,如果没有连接上,用刚才的命令重现尝试一下。

 

完.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值