Since several versions now (don't know which), on canary Android Studio, the avd.sh script is not working anymore because of an extra INFO line shown by emulator command.
#!/usr/bin/sh
# don't show pushd stack
pushd () {
command pushd "$@" > /dev/null
}
pushd ${ANDROID_HOME}/emulator
emuAvds=$(./emulator -list-avds)
# echo "emuAvds: ${emuAvds}" # DEBUG
echo "Emulator Android Virtual Devices:"
avds=$(echo "${emuAvds}" | grep -v ^INFO | cat -n)
echo "${avds}"
ignoredINFO_lines=$(echo ${emuAvds} | grep ^INFO | wc -l)
# echo "number of beginning INFO lines ignored: ${ignoredINFO_lines}"
# eg. INFO line:
# INFO | Storing crashdata in: C:\Users\<user>\AppData\Local\Temp\\AndroidEmulator\emu-crash-34.1.12.db, detection is enabled for process: 8548
printf "Select AVD to start: "
read index
#echo "index: ${index}" # DEBUG
emuAvdsIndex=$((${index} + ${ignoredINFO_lines}))
#echo "emuAvdsIndex: ${emuAvdsIndex}" # DEBUG
avd=$(echo "${emuAvds}" | sed "${emuAvdsIndex}q;d")
echo "Selected ${emuAvdsIndex}: ${avd}"
./emulator -netdelay none -netspeed full -avd "${avd}"
popd
# REF: https://github.com/enieber/open-avd/blob/master/avd.sh
I tested it in git bash in windows on android studio canary.
Would be good to test on current stable android studio emulator before releasing.