Skip to content

Instantly share code, notes, and snippets.

@badsyntax
Last active January 27, 2022 12:03
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save badsyntax/4029600db276b0b51342626aebf9400a to your computer and use it in GitHub Desktop.
Save badsyntax/4029600db276b0b51342626aebf9400a to your computer and use it in GitHub Desktop.
start an android emulator with screen dimensions (specifically for use in CI)
# Install AVD files
yes | $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
@badsyntax
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment