Skip to content

Instantly share code, notes, and snippets.

@mauron85
Created November 21, 2018 17:53
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 mauron85/91b356f703fc4ca8b33699c91d1fffb2 to your computer and use it in GitHub Desktop.
Save mauron85/91b356f703fc4ca8b33699c91d1fffb2 to your computer and use it in GitHub Desktop.
#!/bin/bash
# (@) start-android
# If the emulator command exists on this device, displays a list of emulators
# and prompts the user to start one
# Original source: https://stackoverflow.com/a/41437075/3896616
function assert_sdk {
command -v $1 > /dev/null || {
echo >&2 "Executable \"$1\" not present in your system.";
echo "Did you installed android sdk? Aborting.";
exit 1;
}
}
# Fix Android Emulator
# https://stackoverflow.com/questions/42554337/cannot-launch-avd-in-emulatorqt-library-not-found
function emulator2 { (cd "$(dirname "$(which emulator)")" && ./emulator "$@";) }
assert_sdk emulator
# Gather emulators that exist on this computer
devices=( $(emulator -list-avds 2>&1 ) )
# Display list of emulators
echo "Available Emulators
----------------------------------------"
N=1
for device in ${devices[@]}
do
echo "$N) $device"
let N=$N+1
done
# Request an emulator to start
read -p "
Choose an emulator: " num
# If the input is valid, launch our emulator on a separate PID and exit
if [ $num -lt $N ] && [ $num -gt 0 ];
then
device=${devices[$num-1]}
emulator2 "@$device" & #/dev/null 2>&1 &
exit 0
else
echo "Invalid Entry : $num"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment