Skip to content

Instantly share code, notes, and snippets.

@wbroek
Created October 12, 2017 18:20
Show Gist options
  • Save wbroek/a2caf1ace90eac0c5e25497548f41a6e to your computer and use it in GitHub Desktop.
Save wbroek/a2caf1ace90eac0c5e25497548f41a6e to your computer and use it in GitHub Desktop.
Visual Studio Code task to start the Android Emulator (for React Native development)
{
"version": "2.0.0",
"reveal": "silent",
"tasks": [{
"taskName": "Start Android Emulator",
"type": "shell",
"isBackground": true,
"command": "~/Library/Android/sdk/tools/emulator",
"args": [
"-avd",
"[AVD_NAME]",
">",
"/dev/null",
"2>&1",
"&"
],
"problemMatcher": [],
"presentation": {
"reveal": "never"
}
}]
}
@rafaelmaeuer
Copy link

I am trying to avoid this error by removing "isBackground": true from the task. Then using a shell script which finishes after loading the emulator, but although detaching the process from the terminal using &, nohup or disown, the emulator closes when vscode finishes the prelaunch task.
Running the script in a terminal works as expected, with ctrl + c oder closing the terminal the emulator stays open.

Here is my script:

#!/usr/bin/env bash

# start emulator as headless process
# nohup emulator @Nexus_5X_API_28 -no-boot-anim & disown

# wait for emulator to be started
adb wait-for-device & disown

# wait for android to be booted
while [ "`adb shell getprop sys.boot_completed | tr -d '\r' `" != "1" ] ; do sleep 1; done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment