Working around ADB "waiting for device" issue

Found a way of solving it, so posting here for completeness. Please note that I'm not saying this is the best way of solving it, but it's worked for us.

So, we realised the problem happened after long periods of CI inactivity (in the range of hours). So we created a simple script that calls adb devices every 10 seconds. And the problem is gone, no more "waiting for device" issues.

On Linux you can do this with a simple cron job and on OSX with launchctl and I'm sure there's a Windows equivalent.

Regardless, "pinging" the devices every 10 seconds solved it for us.


Enabling USB debugging (Settings => Developer options) in the phone helped.