Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janaka120/060a01ba2e133cd70b9cd54074a69de3 to your computer and use it in GitHub Desktop.
Save janaka120/060a01ba2e133cd70b9cd54074a69de3 to your computer and use it in GitHub Desktop.
start an android emulator with screen dimensions (specifically for use in CI)
# Install AVD files
$ANDROID_HOME/tools/bin/sdkmanager --install 'system-images;android-29;default;x86'
yes | $ANDROID_HOME/tools/bin/sdkmanager --licenses

# Create emulator
echo "no" | $ANDROID_HOME/tools/bin/avdmanager create avd -n Pixel_API_29_AOSP -d pixel --package 'system-images;android-29;default;x86' --force

$ANDROID_HOME/emulator/emulator -list-avds

# Set screen dimensions
echo "hw.lcd.density=420" >> ~/.android/avd/Pixel_API_29_AOSP.avd/config.ini
echo "hw.lcd.height=1920" >> ~/.android/avd/Pixel_API_29_AOSP.avd/config.ini
echo "hw.lcd.width=1080" >> ~/.android/avd/Pixel_API_29_AOSP.avd/config.ini

echo "Starting emulator and waiting for boot to complete..."
nohup $ANDROID_HOME/emulator/emulator -avd Pixel_API_29_AOSP -no-snapshot -no-window -no-audio -no-boot-anim -camera-back none -camera-front none -qemu -m 2048 > /dev/null 2>&1 &
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do sleep 1; done; input keyevent 82'

echo "Emulator has finished booting"
$ANDROID_HOME/platform-tools/adb devices
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment