Search code examples
androidandroid-studiogoogle-chromedebuggingadb

Android Studio Disconnects From Physical Device


Android Studio Bumblebee (2021.1.1) was released stably on 25 January 2022 bundled with a new Device Manager (accompanying new support for Android 11+ device debugging over WIFI). I jumped on this stable release, updating from Android Studio Arctic Fox (2020.3.1 Patch 4).

Unfortunately however, since updating, physical devices/handsets don't remain connected to Android Studio for the purpose of debugging. I can confirm that the issue was introduced from Android Studio Bumblebee onwards (occurring in Beta and Canary builds also). I've reproduced the issue on Android Studio Bumblebee (Stable), Chipmunk (Beta), and Dolphin (Canary), but Android Studio Arctic Fox (superseded Stable) continues to work just fine.

The issue occurs soon after opening Android Studio (Bumblebee+) with one of my physical devices connected. Everything appears fine initially and I may even have enough time to deploy my project to the handset, before the device disappears from Android Studio (as if I'd physically disconnected the USB cable from my computer or from the handset itself).

I've tried a fair few things in an attempt to determine a root cause. These include testing:

  • With different USB cables.
  • With different handsets (both varying makes and models).
  • With various versions of the Android Studio IDE (as mentioned above).
  • Plugging the USB cables into different USB ports on my computer.
  • Rebooting handsets and my computer.
  • Restarting Android Studio.
  • Invalidating caches and restarting Android Studio.
  • adb kill-server then adb start-server.
  • Revoking/reaccepting USB debugging authorization.
  • Reinstalled build tools/platform tools, and ADB.
  • A great number of further possibilities, to no avail.

I searched and read through remotely similar issues, including (but not limited to) these:

This particular comment in one of the above issues clued me onto a possible root cause:

I have been fighting for a few days with adb not seeing my device. After trying many other posted solutions, I discovered that the issue was with Chrome also trying to connect its debugger to a web view. If Chrome is connected using chrome://inspect, then adb seems to disconnect. Quitting Chrome resolves the issue. Then I can connect with Android Studio and then restart Chrome and reconnect. Hope this helps someone else.

However I've been unable to do anything with the above discovery, other than close Google Chrome, and hope for the best. Obviously this isn't an ideal solution. It appears as though the moment Google Chrome shows the connected physical device in the chrome://inspect/#devices page, the physical device promptly becomes unavailable through Android Studio.

I've jumped back to Android Studio Arctic Fox (2020.3.1 Patch 4) for the moment, however this brings with it other issues (my current core project targets the latest SDK version, which requires the updated IDE).

Absolutely any help with this would be insanely appreciated. I've exhausted just about every avenue that I can think of!


Solution

  • I solved the problem by disabling

    Settings -> Build, Execution, Deployment -> Debugger -> "Enable adb mDNS for wireless debugging"

    adb mDNS settings screenshot