Unity build keeps knocking out existing adb instances, then reports no device connected

I have a separate installation of the Android SDK which has its own adb. Often but not always, when starting a build in Unity, it’ll report that another instance of adb from another SDK is running and have been terminated:

/Users/<me>/Library/Android/sdk/platform-tools/adb```

The problem is that whatever instance of adb Unity may start to pick up devices, the build doesn't give it enough time to actually pick the device up and the build fails saying "No devices sry not sry". It's super frustrating because it's really hard to figure out a reliable workaround that isn't "Close all instances of Android Studio, close all instances of Unity, then restart them in some order such that the problem stops happening." This will even happen when no instances of Android Studio are running because adb will start as a service anyway.

Even more frustrating is that when I kill existing adb instances and let Unity start its own, sometimes the build will still instantly fail with the same error, as it presumably doesn't give even its own instance of adb time to fully connect to any devices.

Enabling Unity to give its own instance of adb enough time to fully connect seems like it Should Be Pretty Simple To Add(tm). It's already checking for existing instances of adb. It can wait with a timeout for that adb instance to list the target device as connected using 'adb devices' and parsing output.

I'm a C++ game dev engineer of 15 years so I appreciate subtleties, so what are the differences between Unity's version of adb versus the version of adb in multiple releases of the Android SDK? Is there any way Unity can check for adb compatibility and just use existing compatible instances? How hard would it really be to have Unity wait for adb to list the target device as connected (or any device when 'All compatible devices' is selected from Build Settings)? Having to restart processes takes time, loses undo/redo histories, and sometimes requires restarting processes multiple times before the bug just magically goes away. This bug happens a few times per day and takes time to right.

Thanks in advance.

This means you have several tools alive using adb from different locations, for ex, Unity, Android Studio, command line, something else. One way to fix this, is to set all your tools to use Android SDK from the same location.

I assume /Users//Library/Android/sdk/platform-tools/ is not used by Unity, but used by some other tool, that’s why when Unity detects adb running from that location, it will try to terminate to avoid adb collisions.

1 Like

Yes, I am aware. We can’t change SDK paths for various projects because our non-Unity projects require the formal Android SDK and Oracle JDK, and our Unity projects can’t be retargeted to either of those (we’ve tried, there’s some pretty big issues there). The question wasn’t how do I fix this, the question was if Unity was going to fix this.

If we can reproduce this locally, we can certainly try to improve the behavior.

You can report the issue here - Unity QA: Building quality with passion, since you have a complex case, try to be as detailed as possible.

With all due respect, this is not a complex case. Install the Android SDK, make sure the SDK’s adb is running, build in Unity. As I said, this happens daily during routine development, it’ll happen eventually.

I’ll file a bug.

I had a similar problem. Ensure your path finds adb first in the current PlayBackEngines folder, mine for example (on Windows) is D:\Program Files\MyUnity\2021.1.27f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platform-tools

I also have this in 2023.1.12f and Android Studio Giraffe.

Unity randomly disconnects my physical Android devices and crashes my emulators with the following error (and they can’t be connected back until I invalidate caches of Android Studio… but then Unity breaks it again and again after a while!):

Multiple ADB server instances found, the following ADB server instance have been terminated due to being run from another SDK. Process paths:
C:\Users\x\AppData\Local\Android\Sdk\platform-tools\adb.exe
Reconnecting Device:
adb-x._adb-tls-connect._tcp
System.Threading._ThreadPoolWaitCallback:PerformWaitCallback ()

So, nothing has been done about this by the entire Unity team for over 1 year?

The bug report of @tbcoins didn’t arrive?

The proposed solution (“One way to fix this, is to set all your tools to use Android SDK from the same location.”) to update SDK, JDK and NDK paths in Preferences > External Tools, to the ones from Android Studio, doesn’t work because the newest Unity (2023.1.12) uses too outdated versions (like NDK v23 when we have v25). Please Unity team give us complete and fully working instructions or a bug fix.

happens over and over