adb无线连接android手机

1.方法一:手机端命令

1.1 手机端打开adb服务,执行命令序列如下:

su
setprop service.adb.tcp.port 5555
stop adbd && start adbd

注明:必须要su,否则start adbd起不来,导致usb与wifi都识别不到手机,需要重新启动手机。


1.2 PC端通过WIFI连接手机

C:\Users\win10>adb connect 192.168.4.150
connected to 192.168.4.150:5555

注:这一步,有的手机要信任该电脑调试。

C:\Users\win10>adb devices
List of devices attached
192.168.4.150:5555      device

1.3 原理如下:

在adb的说明文档中提到:

    “An ADB transport models a connection between the ADB server and one device
    or emulator. There are currently two kinds of transports:
       - USB transports, for physical devices through USB
       - Local transports, for emulators running on the host, connected to
         the server through TCP”

    大意是说,在物理设备上,adb是通过USB连接到设备上的,而在模拟器上,adb是通过TCP协议连接到设备上的。实际上在物理设备上,也可以让adb通过TCP协议来连接设备(当然前提条件是你的设备要有网口)。首先看一下下面这段源代码,出自system/core/adb/adb.c,第921行:

   

   /* for the device, start the usb transport if the
        ** android usb device exists and "service.adb.tcp"
        ** is not set, otherwise start the network transport.
        */
    property_get("service.adb.tcp.port", value, "0");
    if (sscanf(value, "%d", &port) == 1 && port > 0) {
        // listen on TCP port specified by service.adb.tcp.port property
        local_init(port);
    } else if (access("/dev/android_adb", F_OK) == 0) {
        // listen on USB
        usb_init();
    } else {
        // listen on default port
        local_init(ADB_LOCAL_TRANSPORT_PORT);
    }

    分析上述代码可以发现,在adbd启动时首先检查是否设置了service.adb.tcp.port,如果设置了,就是使用TCP作为连接方式;如果没设置,就去检查是否有adb的USB设备(dev/android_adb),如果有就用USB作为连接方式;如果没有USB设备,则还是用TCP作为连接方式。

    因此只需要在启动adbd之前设置service.adb.tcp.port,就可以让adbd选则TCP模式,也就可以通过网络来连接adb了。这需要修改init.rc文件。如果不想修改,也可以在系统启动之后,在控制台上执行以下序列命令


su
setprop service.adb.tcp.port 5555
stop adbd && start adbd

方法二:PC端命令

转:https://futurestud.io/tutorials/how-to-debug-your-android-app-over-wifi-without-root


How to Debug Your Android App over WiFi (without Root!)

I discovered this little trick a year ago and it was immensely helpful. So far, whenever I was working on my Android apps, I had to connect it to my laptop with a USB cable. The USB cable is annoying and limits my movements. Consequently, I was researching, if there is an option to do the debugging over WiFi.

Luckily, there is a super simple way! All you need is a USB cable (for the initial setup) and have both devices in the same network. The screenshots in the following section are from my MacBook Pro, but it works on any operating system.

Steps to Revolutionize your Android Coding Experience

  1. You need to connect your device to your computer via USB cable. Make sure USB debugging is working. You can check if it shows up when running adb devices.

  2. Run adb tcpip 5555

  3. Disconnect your device (remove the USB cable).

  4. Go to the Settings -> About phone -> Status to view the IP address of your phone.

  5. Run adb connect <IP address of your device>:5555

  6. If you run adb devices again, you should see your device.

Now you can execute adb commands or use your favorite IDE for android development - wireless!

Do I Have to Repeat the Process Every Time?

Now you might ask, what do I have to do when I move into a different work space and change WiFi networks? You do not have to repeat steps 1 to 3 (these set your phone into WiFi-debug mode). You do have to connect to your phone again by executing steps 4 to 6.

Unfortunately, the android phones lose the WiFi-debug mode when restarting. Thus, if your battery died, you have to start over. Otherwise, if you keep an eye on your battery and do not restart your phone, you can live without a cable for weeks!

Happy wireless coding!



方法三:使用adbwireless.apk
转:http://blog.csdn.net/bear_huangzhen/article/details/46762613

今天电脑usb接口出问题了,就想着可不可以通过wifi连上手机,然后进行eclipse调试,看logcat等等。


网上搜了一下,果然有这种解决方案。


现在分享给各位Android小伙伴。


前提:需要你的windows电脑已经安装了android sdk。


步骤:

1.关键的东东是需要在你的android手机上安装一个神奇的软件:Adb Wireless (apk下载)


2.在你的手机上安装成功后,图标如图:



3.进入该app,界面如下,点击中间那个很大的按钮,下方会出现连接信息:



4.你需要确保adbWireless这个app获得了你手机的root权限,如果你不确定,可以进入授权管理查看:



5.找到你电脑中安装sdk的地方,运行----->cmd----->cd到sdk目录下的platform-tools目录,

然后敲入第3步中黄色框线框住的内容,我这里是:adb connect 192.168.1.105




当出现connected to字样的时候表明你电脑与手机的无线连接已经成功了,这个时候我们打开eclipse的devices和logcat视图,你会发现真的成功了:




apk wireless.apk 的源码

https://github.com/haikuowuya/adb_wireless



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值