Created
September 1, 2021 02:25
-
-
Save gtfunes/5e80e690d427d809a83e1c83259636dd to your computer and use it in GitHub Desktop.
Start Android AVD from CLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# - Selects an AVD emulator and boots it up - | |
HAS_DEVICE=$(adb get-state 2>/dev/null) | |
if [ ! -z "$HAS_DEVICE" ]; then | |
echo "A device is connected, nothing to do here..." | |
exit | |
fi | |
DEFAULT_DIR=$HOME/Library/Android/sdk | |
EMULATOR_DIR=${ANDROID_HOME} | |
if [ ! -d "$EMULATOR_DIR" ]; then | |
EMULATOR_DIR=${DEFAULT_DIR} | |
fi | |
if [ ! -d "$EMULATOR_DIR" ]; then | |
echo "ERROR: Couldn't find AVD directory" | |
exit | |
fi | |
pushd ${EMULATOR_DIR}/emulator > /dev/null | |
printf "Available devices:\n" | |
./emulator -list-avds | cat -n | |
printf "\nSelect a device: " | |
read index | |
avd=$(./emulator -list-avds | sed "${index}q;d") | |
echo "Selected $avd\n" | |
nohup ./emulator -avd $avd -no-boot-anim -no-snapshot-save -netfast >/dev/null & | |
../platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; do sleep 1; done;' | |
echo "Device booted!\n\n" | |
popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment