Skip to content

Commit 4dc2920

Browse files
feat: enhance Android emulator setup with disk space cleanup and dynamic disk size configuration
1 parent 72acbdd commit 4dc2920

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

.github/workflows/android.yml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ env:
88
DEVICE_ARCH: 'x86_64'
99
DEVICE_TARGET: 'google_apis'
1010
AVD_NAME: 'Pixel_API_35'
11+
EMULATOR_DISK_SIZE: '8G'
1112
ANDROID_SDK_ROOT: /usr/local/lib/android/sdk
1213
ANDROID_HOME: /usr/local/lib/android/sdk
1314
NDK_VERSION: '27.3.13750724'
@@ -50,6 +51,25 @@ jobs:
5051
sudo udevadm trigger --name-match=kvm
5152
ls /dev/kvm
5253
54+
- name: Free Disk Space
55+
shell: bash
56+
run: |
57+
set -euo pipefail
58+
59+
echo "Disk space before cleanup:"
60+
df -h
61+
62+
# GitHub-hosted runners come with extra SDKs/toolchains preinstalled.
63+
# Removing a few of the largest ones gives the Android emulator enough
64+
# room to create its userdata partition.
65+
sudo rm -rf /usr/share/dotnet || true
66+
sudo rm -rf /opt/ghc || true
67+
sudo rm -rf /usr/local/share/boost || true
68+
sudo rm -rf /usr/share/swift || true
69+
70+
echo "Disk space after cleanup:"
71+
df -h
72+
5373
- name: Cache Gradle
5474
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.2.0
5575
with:
@@ -70,22 +90,24 @@ jobs:
7090

7191
- name: AVD cache
7292
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.2.0
93+
id: avd-cache
7394
with:
7495
path: |
7596
~/.android/avd/*
7697
~/.android/adb*
77-
key: avd-${{ env.DEVICE_API_LEVEL }}-${{ env.DEVICE_ARCH }}
98+
key: avd-${{ env.DEVICE_API_LEVEL }}-${{ env.DEVICE_TARGET }}-${{ env.DEVICE_ARCH }}-${{ env.EMULATOR_DISK_SIZE }}
7899

79100
# Create AVD (only if not cached, runs after build)
80101
- name: Create AVD and generate snapshot for caching
102+
if: steps.avd-cache.outputs.cache-hit != 'true'
81103
uses: reactivecircus/android-emulator-runner@b530d96654c385303d652368551fb075bc2f0b6b # v2.33.0
82104
with:
83105
api-level: ${{ env.DEVICE_API_LEVEL }}
84106
target: ${{ env.DEVICE_TARGET }}
85107
arch: ${{ env.DEVICE_ARCH }}
86108
ram-size: 4096M
87-
disk-size: 6G
88-
force-avd-creation: false
109+
disk-size: ${{ env.EMULATOR_DISK_SIZE }}
110+
force-avd-creation: true
89111
avd-name: ${{ env.AVD_NAME }}
90112
disable-animations: true
91113
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -memory 4096
@@ -100,6 +122,7 @@ jobs:
100122
target: ${{ env.DEVICE_TARGET }}
101123
arch: ${{ env.DEVICE_ARCH }}
102124
ram-size: 4096M
125+
disk-size: ${{ env.EMULATOR_DISK_SIZE }}
103126
force-avd-creation: false
104127
avd-name: ${{ env.AVD_NAME }}
105128
disable-animations: true

0 commit comments

Comments
 (0)