Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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