Android Studio: 通过WiFi连接时,物理设备在设备管理器中会自动断开连接

huangapple go评论132阅读模式
英文:

Android Studio: Physical Device disconnects automatically from Device Manager while connected via WiFi

问题

我曾经通过无线模式(Wi-Fi)将我的物理设备与Android Studio连接。第一次连接物理设备时,使用设备管理器很容易连接。但是在1-2小时或系统进入睡眠模式后,即使通过Wi-Fi连接,物理设备最终会自动从设备管理器断开连接。

我有一台搭载macOS Monterey操作系统的MacBook Air,我使用的是最新版本的Android Studio。

实际遇到的问题:

我的设备在已经通过WiFi连接后,过一段时间会自动断开连接。我尝试了两种方法 - "使用QR码配对"和"使用配对码配对"来连接设备和我的机器(MacBook)。设备显示已连接,但机器只显示"连接中",并且永远无法完全连接。几分钟后,它显示错误消息。
然而,有时它会在我什么都不做的情况下自动重新连接。

> 在从设备管理器断开连接后,我通常会使用电缆连接,因为设备管理器只会显示几分钟的"连接中",然后显示错误。

我弄清楚为什么有时会自动断开连接:

  • Wi-Fi无法连接或从网络断开
  • 设备要么切换Wi-Fi网络,要么从网络断开
  • 机器和设备未连接到相同的无线网络
  • 机器或设备在一段时间内处于闲置状态
  • 有时会无故自动断开连接(这是我遇到的实际问题)

我尝试过但未获得预期结果的方法:

  • 在相同的无线网络上重新连接机器和设备
  • 使缓存失效并重新启动Android Studio
  • 重新启动Android Studio
  • 撤销/重新接受USB调试授权
  • 尝试不同的连接方式,使用"使用QR码配对"或"使用配对码配对"
  • 我还查看了官方文档,但没有找到合适的解决方案:排查设备连接问题

查看其他类似问题:
我已经查看了Stack Overflow上关于同样问题的问题,但没有找到合适的解决方案。

英文:

I used to connect my physical device with Android Studio via wireless mode (Wi-Fi). On the first time, when I connect my physical device using Device Manager, it connects easily. But after 1-2 hour or when system goes in sleep mode, Eventually physical device discoonects automatically from the Device Manager even when connected via WiFi.

I have a MacBook Air with the macOS Monterey operating system, and I'm using the latest version of Android Studio.

Android Studio: 通过WiFi连接时,物理设备在设备管理器中会自动断开连接

Issue I'm actually facing:

My device disconnects automatically after sometime when I already connected via WiFi. I've tried both methods - "Pair using QR code" and "Pair using pairing code" to connect the device and my Machine (MacBook). The device shows that it's connected, but the machine just says "connecting" and never fully connects. After a few minutes, it shows an error message.
However, sometimes it reconnects automatically without me doing anything.

> After disconnecting from the Device Manager, I used to connect using the cable connectivity because Device Manager just shows connecting for a few minutes and then shows an error.

I figured out why it sometimes disconnects on its own:

  • Wi-Fi is not connecting or disconnects from the network
  • Device either switch Wi-Fi networks or disconnects from the network
  • Machine and device are not connected to the same wireless network
  • Machine or Device goes idle for sometime
  • Sometimes disconnected automatically without any reason (That's the actual issue which I facing)

Ways I tried but didn't get the expected results:

  • Re-connected Machine and Device on the same wireless network
  • Invalidating caches and restarting Android Studio
  • Restarting Android Studio
  • Revoking/reaccepting USB debugging authorization
  • Try connecting in a different way by using either "Pair using QR code" or "Pair using pairing code"
  • I also looked at the official documentation but not fount a suitable solution: Troubleshoot device connection

Reviewed other similar questions:
I have examined questions already posted on Stack Overflow regarding the same issue, but I have not found a suitable solution.

答案1

得分: 0

我不是Mac用户,但在Windows上,与Android的WiFi连接也有问题。我曾经经历过你所经历的同样错误。目前还没有解决方案。但是,有一种方法可以确保它百分之百正常工作。

  • 笔记本电脑将连接到WiFi。

  • 笔记本电脑将打开一个移动热点(我不知道Mac上是否可用)。

  • 手机的WiFi将连接到该热点。

  • 第一次使用代码进行配对,然后始终连接

    ./adb connect 192.168.137.254:37785
    

==> 这样永远都会正常工作。如果没有热点,你将会遇到各种问题。

英文:

I am not a Mac user, but on Windows, the wifi connection to Android is also buggy. I have experienced the same error that you experience. There is no solution for that. But, there is a way to make it work 100%.

  • The laptop will connect to the WiFi.

  • Laptop will open a Mobile hotspot (idk if it is available in Mac)

  • Mobile's Wifi will connect to that hotspot.

  • for the first time pair with code and then always connect

    ./adb connect 192.168.137.254:37785

==> This will always work. Without a hotspot, you will experience all sorts of problems.

答案2

得分: 0

在调试时,我认为 Android Studio 中存在故障,但结果完全不同。我调试了这个问题,发现移动设备也是 Android Studio 通过 Wi-Fi 连接时自动断开连接的原因。

只需重新启动物理设备,然后尝试使用 Android Studio 中的 使用 QR 码配对设备使用配对码配对设备 重新连接设备管理器。它百分之百有效。

另一种方法:

  • 进入 设置
  • 选择 开发者选项
  • 关闭 无线调试
  • 点击 "撤销 USB 调试授权"
  • 再次打开 无线调试 并允许无线调试
  • 现在可以使用 Android Studio 中的 使用 QR 码配对设备使用配对码配对设备 将设备与设备管理器配对。
英文:

While debugging I thought, There is a glitch in the Android Studio but the results are totally different. I debugged the issue & found mobile device is also a cause of auto-disconnecting from the Device Manager while connected via Wi-Fi in Android Studio.

> Just Restart the physical device & try to reconnect with Device Manager in Android Studio using the Pair device with QR code or Pair device with pairing code. It works 100%.

Another Way:

  • Go to Settings
  • Select Developer options
  • Turn off Wireless debugging
  • Click on "Revoke USB debugging authorisations"
  • Again turn on Wireless debugging and Allow wireless debugging
  • Now pair the device using Pair device with QR code or Pair device with pairing code with Device Manager in Android Studio

huangapple
  • 本文由 发表于 2023年7月17日 16:50:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76702819.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定