isleofcode / corber

CLI for building hybrid apps with Ember/Vue/Glimmer/Cordova
http://corber.io
MIT License
334 stars 100 forks source link

Race condition causing "No emulators or devices found" for Android #635

Open YoranBrondsema opened 5 years ago

YoranBrondsema commented 5 years ago

Hi,

I'm trying to set up my new Ember.js project with Android. And I came upon the same issue described here and it looks like there's some race condition going on.

I don't have a device connected, only a single emulator. With the following lines in lib/commands/start.js as they are now:

if (platforms.includes('android')) {
  promises.push(listAndroidDevices());
  promises.push(listAndroidEmulators());
}

it finds my emulator about 10% of the time when running corber start. The other 90% of the time, it outputs No emulators or devices found.

However, when I ask it to list the emulators before the devices:

if (platforms.includes('android')) {
  promises.push(listAndroidEmulators());
  promises.push(listAndroidDevices());
}

it finds the emulator 100% of the time!

So it seems that there's a race condition (or something similar) between the two commands

$ANDROID_SDK_ROOT/emulator/emulator -list-avds (lists emulators)
$ANDROID_SDK_ROOT/platform-tools/adb devices -l (lists devices)

I'm new to Android development so I really don't know what's going on here. Just wanted to document this. Maybe it's an option to run the two commands in serial rather than in parallel? I know it's not ideal without understanding the root cause, but it might offer a solution for some people in the mean time without affecting functionality.

I'm on Linux btw (Ubuntu 18.04).

alexblom commented 4 years ago

Interesting - thanks for reporting this - and for the detailed repro case :-)