From a4164c89a0aa521b3b88c72cc5e6aba0f2edddf9 Mon Sep 17 00:00:00 2001 From: John Knox Date: Fri, 26 Apr 2019 03:39:02 -0700 Subject: [PATCH] Fix emulator usage on linux Summary: emulator isn't on the path in CI machines, but we already have ANDROID_HOME set so we can work out where it is. Reviewed By: danielbuechele Differential Revision: D15080422 fbshipit-source-id: 2c50a3de27909d2bfc82ea0210d06a0cc32357d7 --- src/chrome/DevicesButton.js | 1 + src/dispatcher/androidDevice.js | 34 +++++++++++++++++---------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/chrome/DevicesButton.js b/src/chrome/DevicesButton.js index c6a7f9f06..ac9165772 100644 --- a/src/chrome/DevicesButton.js +++ b/src/chrome/DevicesButton.js @@ -40,6 +40,7 @@ class DevicesButton extends Component { // On Linux, you must run the emulator from the directory it's in because // reasons ... whichPromise('emulator') + .catch(e => `${process.env.ANDROID_HOME || ''}/tools/emulator`) .then(emulatorPath => { const child = spawn(emulatorPath, [`@${name}`], { detached: true, diff --git a/src/dispatcher/androidDevice.js b/src/dispatcher/androidDevice.js index 3f51764ce..8d717272f 100644 --- a/src/dispatcher/androidDevice.js +++ b/src/dispatcher/androidDevice.js @@ -64,22 +64,24 @@ function getRunningEmulatorName(id: string): Promise { export default (store: Store, logger: Logger) => { const watchAndroidDevices = () => { // get emulators - promisify(which)('emulator').then(emulatorPath => { - child_process.exec( - `${emulatorPath} -list-avds`, - (error: ?Error, data: ?string) => { - if (error != null || data == null) { - console.error(error || 'Failed to list AVDs'); - return; - } - const payload = data.split('\n').filter(Boolean); - store.dispatch({ - type: 'REGISTER_ANDROID_EMULATORS', - payload, - }); - }, - ); - }); + promisify(which)('emulator') + .catch(e => `${process.env.ANDROID_HOME || ''}/tools/emulator`) + .then(emulatorPath => { + child_process.exec( + `${emulatorPath} -list-avds`, + (error: ?Error, data: ?string) => { + if (error != null || data == null) { + console.error(error || 'Failed to list AVDs'); + return; + } + const payload = data.split('\n').filter(Boolean); + store.dispatch({ + type: 'REGISTER_ANDROID_EMULATORS', + payload, + }); + }, + ); + }); getAdbClient() .then(client => {