Skip to content

Instantly share code, notes, and snippets.

@DeuceTheCoder
Created February 10, 2015 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DeuceTheCoder/f0715465806c7e2e754d to your computer and use it in GitHub Desktop.
Save DeuceTheCoder/f0715465806c7e2e754d to your computer and use it in GitHub Desktop.
Starts an existing android emulator and waits for it to be ready
#!/bin/bash
DEVICE_WAIT_TIMEOUT='3m'
function start_emulator_and_unlock_screen {
emulator_name=$1
shift
emulator_options=$*
check_emu_name $emulator_name
$ANDROID_HOME/tools/emulator @$emulator_name $emulator_options &
EMULATOR_ID=$!
wait_for_device
echo "Android emulator is started with PID $EMULATOR_ID"
#uncomment if device has a lockscreen enabled
#$ANDROID_HOME/platform-tools/adb shell input keyevent 82
}
#TODO: use android list avd to check that the name is an existing AVD
function check_emu_name {
if [ -z "$1" ]
then
echo "The first parameter must be the name of an existing AVD"
exit
fi
}
function wait_for_device {
echo 'Waiting for Android device to be started/connected'
timeout $DEVICE_WAIT_TIMEOUT $ANDROID_HOME/platform-tools/adb wait-for-device
}
start_emulator_and_unlock_screen $*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment