Fix emulator launching on Linux

Summary:
The Android SDK installation on Linux is really dumb. The emulator binary
is dynamically linked and ships with some `.so`s that need to be either in `LD_LIBRARY_PATH` or `$CWD`.
For some reason, there's no script, so you have to manually `cd` into the directory in order to
run it. ¯\_(ツ)_/¯

Reviewed By: jknoxville

Differential Revision: D13589660

fbshipit-source-id: e3bdd7468108f1fb1e52f23ae45e21cacc5480f9
This commit is contained in:
Pascal Hartig
2019-01-07 07:44:56 -08:00
committed by Facebook Github Bot
parent 5173b22760
commit 7471dc6481
4 changed files with 32 additions and 8 deletions

View File

@@ -8,9 +8,14 @@
import {Component, Button, styled} from 'flipper';
import {connect} from 'react-redux';
import {spawn} from 'child_process';
import {dirname} from 'path';
import {selectDevice, preferDevice} from '../reducers/connections.js';
import {default as which} from 'which';
import {promisify} from 'util';
import type BaseDevice from '../devices/BaseDevice.js';
const whichPromise = promisify(which);
type Props = {
selectedDevice: ?BaseDevice,
androidEmulators: Array<string>,
@@ -27,13 +32,18 @@ const DropdownButton = styled(Button)({
/* eslint-disable prettier/prettier */
class DevicesButton extends Component<Props> {
launchEmulator = (name: string) => {
const child = spawn('emulator', [`@${name}`], {
detached: true,
});
child.stderr.on('data', data => {
console.error(`Android emulator error: ${data}`);
});
child.on('error', console.error);
// On Linux, you must run the emulator from the directory it's in because
// reasons ...
whichPromise('emulator').then(emulatorPath => {
const child = spawn(emulatorPath, [`@${name}`], {
detached: true,
cwd: dirname(emulatorPath),
});
child.stderr.on('data', data => {
console.error(`Android emulator error: ${data}`);
});
child.on('error', console.error);
}).catch(console.error);
this.props.preferDevice(name);
};