Skip to content

Instantly share code, notes, and snippets.

@richkeenan
Created February 12, 2020 10:48
Show Gist options
  • Save richkeenan/f5ae81ff9b3efee30f75e4b459ec30a9 to your computer and use it in GitHub Desktop.
Save richkeenan/f5ae81ff9b3efee30f75e4b459ec30a9 to your computer and use it in GitHub Desktop.
export ANDROID_HOME=/Users/$USER/Library/Android/sdk
RUNNING_EMU="$($ANDROID_HOME/platform-tools/adb devices | grep emulator -c)"
if [[ $RUNNING_EMU -eq 0 ]]
then
# If we're not given an AVD to run on let's find a suitable one to use
if [ $# -eq 0 ]
then
# if Pixel exists (dev has run the setup scripts) run that
if [ -f $HOME/.android/avd/Pixel.ini ]
then
echo "No AVD supplied, but Pixel exists this will be used"
AVD='Pixel'
else
# Pixel AVD doesn't exist so just pick the first in the list
echo "No AVD supplied, using first device in AVD list"
AVD="$($ANDROID_HOME/emulator/emulator -list-avds | head -n 1)"
fi
else
AVD=$1
fi
echo "Android emulator not running, starting new instance $AVD"
nohup $ANDROID_HOME/emulator/emulator -avd $AVD &
else
echo 'Android emulator already running so not starting new instance'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment