Skip to content

Instantly share code, notes, and snippets.

@mrk-han
Created October 20, 2022 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrk-han/dd453c8c06f801adac0c15ce29936ae0 to your computer and use it in GitHub Desktop.
Save mrk-han/dd453c8c06f801adac0c15ce29936ae0 to your computer and use it in GitHub Desktop.
Installing HAXM on GitHub Action macOS-11 and macOS-12 agents
# Minorly adjusted from https://gist.github.com/badsyntax/ce848ab40b952d944c496575d40e5427 and https://github.com/igorboskovic3/actions-test/actions/runs/3239143575/workflow
name: HAXM Installation before Android Test Snippet
# Controls when the workflow will run
on:
workflow_dispatch:
jobs:
install-haxm-and-run-emulator:
runs-on: macos-12
timeout-minutes: 30 # No default
env:
JAVA_TOOL_OPTIONS: -Xmx4g
GITHUB_WORKSPACE: ${{ github.workspace }}
GITHUB_RUN_NUMBER: ${{ github.run_number }}
steps:
- name: Create Android emulator
run: |
# Install HAXM
brew install --cask intel-haxm
# Install AVD files
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --install "system-images;android-30;aosp_atd;x86"
echo "y" | $ANDROID_HOME/tools/bin/sdkmanager --licenses
# Create emulator
$ANDROID_HOME/tools/bin/avdmanager create avd -n API_30_AOSP_ATD -d 'Nexus One' --package "system-images;android-30;aosp_atd;x86"
$ANDROID_HOME/emulator/emulator -list-avds
$ANDROID_HOME/emulator/emulator -accel-check 2>&1 | tee "$GITHUB_WORKSPACE"/haxm-check-"$GITHUB_RUN_NUMBER".txt
if false; then
emulator_config=~/.android/avd/API_30_AOSP_ATD.avd/config.ini
# The following madness is to support empty OR populated config.ini files,
# the state of which is dependant on the version of the emulator used (which we don't control),
# so let's be defensive to be safe.
# Replace existing config (NOTE we're on MacOS so sed works differently!)
sed -i .bak 's/hw.lcd.density=.*/hw.lcd.density=420/' "$emulator_config"
sed -i .bak 's/hw.lcd.height=.*/hw.lcd.height=1920/' "$emulator_config"
sed -i .bak 's/hw.lcd.width=.*/hw.lcd.width=1080/' "$emulator_config"
# Or, add new config
if ! grep -q "hw.lcd.density" "$emulator_config"; then
echo "hw.lcd.density=420" >> "$emulator_config"
fi
if ! grep -q "hw.lcd.height" "$emulator_config"; then
echo "hw.lcd.height=1920" >> "$emulator_config"
fi
if ! grep -q "hw.lcd.width" "$emulator_config"; then
echo "hw.lcd.width=1080" >> "$emulator_config"
fi
echo "Emulator settings ($emulator_config)"
cat "$emulator_config"
fi
# Optionally enable skia rendering https://developer.android.com/studio/run/emulator-acceleration#skia-emulator
$ANDROID_HOME/platform-tools/adb shell 'su;setprop debug.hwui.renderer skiagl;stop;start'
- name: Start Android emulator
run: |
echo "Starting emulator and waiting for boot to complete...."
ls -la $ANDROID_HOME/emulator
nohup $ANDROID_HOME/tools/emulator -avd API_30_AOSP_ATD -gpu swiftshader_indirect -no-audio -no-boot-anim -camera-back none -camera-front none -partition-size 2048 -qemu -m 2048 2>&1 &
$ANDROID_HOME/platform-tools/adb wait-for-device shell 'while [[ -z $(getprop sys.boot_completed | tr -d '\r') ]]; do echo "wait..."; sleep 1; done; input keyevent 82'
echo "Emulator has finished booting"
$ANDROID_HOME/platform-tools/adb devices
# Take Screenshot of VM to verify emulator start
screencapture screenshot.jpg
# Take picture of emulator to verify emulator start
$ANDROID_HOME/platform-tools/adb exec-out screencap -p > emulator.png
- name: install recorder and record session
run: |
brew install ffmpeg
$ANDROID_HOME/tools/emulator -port 18725 -verbose -no-window -no-audio -gpu swiftshader_indirect @Pixel_API_29_AOSP &
ffmpeg -f avfoundation -i 0 -t 120 out.mov
# node -e "const exec = require('child_process'); exec.exec('ffmpeg -f avfoundation -i 0 -t 120 out.mov'); exec.exec('$ANDROID_HOME/tools/emulator -port 18725 -verbose -no-window -no-audio -gpu swiftshader_indirect @Pixel_API_29_AOSP &');"
env:
HOMEBREW_NO_INSTALL_CLEANUP: 1
- name: upload video
uses: actions/upload-artifact@master
with:
name: out
path: out.mov
- uses: actions/upload-artifact@v3
with:
name: screenshot.jpg
path: screenshot.jpg
- uses: actions/upload-artifact@v3
with:
name: emulator.png
path: emulator.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment