adb无线连接android手机

本文介绍三种实现无线ADB调试的方法:手机端命令配置、PC端命令配置及使用adbWireless APK。通过这些方法,开发者可以在无需USB连接的情况下进行Android应用调试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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



### 解决Ubuntu系统中ADB连接手机的问题 在Ubuntu系统中,解决ADB连接手机的问题通常涉及以下几个方面:安装必要的软件包、配置USB规则以及排查可能的连接问题。 #### 1. 安装ADB工具 确保已安装Android Debug Bridge (ADB) 工具。可以使用以下命令来安装`adb`和`fastboot`工具: ```bash sudo apt update sudo apt install -y android-tools-adb android-tools-fastboot ``` 如果上述命令不可用,可以尝试从Android SDK平台工具中手动下载并安装[^3]。 #### 2. 配置USB规则 为了使ADB能够正确识别设备,需要为设备添加适当的udev规则。执行以下步骤: - 创建一个新的udev规则文件: ```bash sudo nano /etc/udev/rules.d/51-android.rules ``` - 在文件中添加以下内容(将`0xXXXX`替换为设备厂商ID): ```bash SUBSYSTEM=="usb", ATTR{idVendor}=="XXXX", MODE="0666", GROUP="plugdev" ``` - 应用新的规则并重新加载udev: ```bash sudo service udev reload sudo service udev restart ``` - 确保当前用户属于`plugdev`组: ```bash sudo usermod -aG plugdev $LOGNAME ``` - 重新插拔设备以应用更改。 #### 3. 检查设备是否被识别 运行以下命令检查设备是否被正确识别: ```bash adb devices ``` 如果没有列出任何设备,请确保手机已启用开发者选项和USB调试功能,并选择正确的USB连接模式(如“文件传输”或“PTP”模式)[^4]。 #### 4. 断开特定设备 如果需要断开某个特定设备,可以使用以下命令: ```bash adb disconnect <device_ip>:<port> ``` 例如: ```bash adb disconnect 192.168.1.10:5555 ``` #### 5. 排查常见问题 - **权限问题**:如果遇到权限错误,尝试使用`sudo adb devices`运行命令。 - **驱动问题**:确保手机厂商提供了适当的Linux驱动支持。 - **网络连接问题**:如果通过Wi-Fi连接设备,确保设备和电脑在同一网络下,并正确设置了IP地址和端口[^5]。 ```bash adb tcpip 5555 adb connect <device_ip>:5555 ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值