adb如何通过wifi连接手机

本文详细介绍了如何使用ADB将Android设备与PC连接到同一无线热点的方法,包括USB连接、设置tcpip模式、查找设备IP地址、通过IP连接设备及中断后的解决策略。

From:http://developer.android.com/tools/help/adb.html

adb is usually used over USB. However, it is also possible to use over Wi-Fi, as described here.

  1. Connect Android device and adb host computer to a common Wi-Fi network accessible to both. We have found that not all access points are suitable; you may need to use an access point whose firewall is configured properly to support adb. 译:手机需与PC连接到同一个无线热点。
  2. Connect the device with USB cable to host.
  3. Make sure adb is running in USB mode on host. 译:通过USB连接手机
    $ adb usb
    restarting in USB mode
  4. Connect to the device over USB.译:执行以下命令查看adb连接列表。注:执行第三步命令后,可能会一直停在那里,需新开cmd窗口执行下述命令
    $ adb devices
    List of devices attached
    ######## device
  5. Restart host adb in tcpip mode.译:设置为tcpip模式
    $ adb tcpip 5555
    restarting in TCP mode port: 5555
  6. Find out the IP address of the Android device: Settings -> About tablet -> Status -> IP address. Remember the IP address, of the form #.#.#.#. 译:查看当前手机获取ip:设置->关于手机->状态消息->ip地址
  7. Connect adb host to device: 译:在cmd命令行下,通过adb connect ip地址 命令连接到手机
    $ adb connect #.#.#.#
    connected to #.#.#.#:5555
  8. Remove USB cable from device, and confirm you can still access device:译:拔出USB线,并查看adb连接列表确认是通过ip连接
    $ adb devices
    List of devices attached
    #.#.#.#:5555 device

You're now good to go!

If the adb connection is ever lost:

  1. Make sure that your host is still connected to the same Wi-Fi network your Android device is.
  2. Reconnect by executing the "adb connect" step again. 译:如果出现中断可以重新执行第7步的connect命令
  3. Or if that doesn't work, reset your adb host: 译: 或者杀死adb server进程后重新执行上述命令。
    adb kill-server
    and then start over from the beginning.
通过WiFi使用ADB连接设备是一种常见的无线调试方式,允许开发者在不使用USB线缆的情况下与Android设备进行交互。以下是实现方法及关键步骤: ### 1. 确保设备和电脑处于同一局域网 首先,确保Android设备和开发用的计算机连接到同一个Wi-Fi网络。这是建立无线ADB连接的前提条件[^3]。 ### 2. 启用设备上的开发者选项和ADB调试模式 在Android设备上启用开发者选项(Developer Options),并在其中开启“USB调试”(USB Debugging)功能。这一步通常需要在设置(Settings)→关于手机(About Phone)中连续点击版本号以激活开发者选项菜单[^4]。 ### 3. 使用USB连接设备并配置TCP/IP端口 将设备通过USB连接到计算机,并在命令行工具中执行以下命令来切换ADB服务为TCP/IP模式: ```bash adb tcpip 5555 ``` 该命令会重启设备上的ADB服务,并将其监听端口设置为5555[^2]。 ### 4. 获取设备IP地址 在设备上打开终端模拟器应用或通过`adb shell`命令,运行如下命令获取设备当前的IP地址: ```bash ifconfig wlan0 ``` 或者使用更简洁的方式: ```bash adb shell ip route show ``` 输出结果中将包含设备的本地IP地址,例如 `192.168.1.136`[^2]。 ### 5. 建立无线连接 现在可以断开USB连接,在命令行中执行以下命令来通过Wi-Fi连接设备: ```bash adb connect 192.168.1.136:5555 ``` 如果一切正常,系统会显示连接成功的信息,并且可以通过`adb devices`命令查看当前已连接的设备列表[^1]。 ### 6. 验证连接状态 运行以下命令验证设备是否已经成功通过Wi-Fi连接: ```bash adb devices ``` 输出结果中应包含设备的IP地址及其状态为`device`,表明连接有效[^1]。 ### 7. 切换回USB连接(可选) 如果需要重新通过USB进行调试,可以在命令行中执行: ```bash adb usb ``` 此命令会将ADB服务切换回USB连接模式。 ### 注意事项 - **环境变量配置**:确保计算机的环境变量中已添加ADB工具路径,否则可能遇到`adb command not found`错误。可以通过编辑`.bash_profile`或`.zshrc`文件来添加路径并使其生效[^3]。 - **Root权限**:某些情况下,特别是在较旧版本的Android系统中,可能需要具备root权限才能修改ADB端口设置[^4]。 - **插件辅助**:对于IDE(如Android Studio),可以安装ADB WiFi Connect等插件来简化无线连接流程。插件通常提供图形界面,方便用户查看设备状态并一键连接[^5]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值