Skip to content

Instantly share code, notes, and snippets.

@whalemare
Created December 26, 2019 06:40
Show Gist options
  • Save whalemare/bfcf92e0172e99fd53c41d669efe762e to your computer and use it in GitHub Desktop.
Save whalemare/bfcf92e0172e99fd53c41d669efe762e to your computer and use it in GitHub Desktop.
Run Android emulator from command line
#! /bin/bash
# This script helped to you start emulator from cli
# Check if the emulator command exists first
if ! type emulator > /dev/null; then
export PATH=${PATH}:~/Library/Android/sdk/emulator
fi
if ! type emulator > /dev/null; then
echo "emulator command not found"
exit 1
fi
# 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]}
emulator "@$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