#! /bin/bash
# (@) start-android
# If the emulator command exists on this device, displays a list of emulators
# and prompts the user to start one
# Check if the emulator command exists first
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
下面是一个运行和输出的例子:
./start-android.sh
Available Emulators
----------------------------------------
1) Nexus_5X_API_23
2) Nexus_9_API_23
Choose an emulator: 1
PS C:\Users\ShahidSiddiqui\.android\avd> emulator -avd HighRAM_Custom_API_30-Clone
emulator: Android emulator version 30.5.5.0 (build_id 7285888) (CL:N/A)
handleCpuAcceleration: feature check for hvf
added library vulkan-1.dll
Failed to open /qemu.conf, err: 2
Windows Hypervisor Platform accelerator is operational
emulator: INFO: GrpcServices.cpp:301: Started GRPC server at 127.0.0.1:8554, security: Local
一个甜蜜的 AVD 将被推出。
干杯!
NOTE: adb devices command will only list the currently running avds and real android devices. It will not show emulators (i.e. avds configured).