Skip to content

Instantly share code, notes, and snippets.

@wbroek
Created October 12, 2017 18:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • 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"
}
}]
}
@wbroek
Copy link
Author

wbroek commented Oct 12, 2017

Create this task as a preLaunchTask for the launch.json so the Android emulator is started before react native is started

@rafaelmaeuer
Copy link

Hi @wbroek,

thanks for sharing this, I was searching for something like this.
But there is a problem which is discussed here link.
After 10 seconds I get the warning "The specified task cannot be tracked".

bildschirmfoto 2018-10-05 um 12 12 41

Seems like vscode is waiting for an answer to check if the preLaunchTask was startet successfully.
I could choose "Debug anyway" but doing this every build is annoying!

Did you faced this problem? Regards

@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