Skip to content

Commit e2d7de5

Browse files
fix: apply fixes
1 parent 5a29ed8 commit e2d7de5

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

.maestro/scripts/setup-android-emulator.sh

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ if [ -z "$ANDROID_HOME" ]; then
2020
exit 1
2121
fi
2222

23+
# Ensure avdmanager and emulator use the same AVD directory regardless of
24+
# what ANDROID_SDK_HOME is set to on the host (e.g. GitHub Actions runners).
25+
export ANDROID_AVD_HOME="$HOME/.android/avd"
26+
mkdir -p "$ANDROID_AVD_HOME"
27+
2328
for tool in sdkmanager avdmanager emulator adb; do
2429
if ! command -v "$tool" &>/dev/null; then
2530
echo "Error: '$tool' not found. Ensure Android SDK tools are installed and in PATH."
@@ -41,24 +46,20 @@ fi
4146

4247
if ! avdmanager list avd -c | grep -qx "${AVD_NAME}"; then
4348
echo "Creating AVD '$AVD_NAME'..."
44-
echo "no" | avdmanager create avd \
45-
--name "$AVD_NAME" \
46-
--device "$DEVICE_ID" \
47-
--package "$SYSTEM_IMAGE" \
48-
--skin "$DEVICE_ID"
49+
CREATE_CMD=(avdmanager create avd --name "$AVD_NAME" --device "$DEVICE_ID" --package "$SYSTEM_IMAGE")
50+
# Skin is cosmetic (phone frame). Skip it on CI since the runner has no skin files
51+
# and the emulator runs headless anyway.
52+
[ -z "${CI:-}" ] && CREATE_CMD+=(--skin "$DEVICE_ID")
53+
echo "no" | "${CREATE_CMD[@]}"
4954
fi
5055

5156
AVD_CONFIG="$HOME/.android/avd/${AVD_NAME}.avd/config.ini"
5257
if [ -f "$AVD_CONFIG" ]; then
53-
if [ "$(uname)" = "Darwin" ]; then
54-
SED_INPLACE=(-i '')
55-
else
56-
SED_INPLACE=(-i)
57-
fi
58-
sed "${SED_INPLACE[@]}" 's/^hw\.keyboard=.*/hw.keyboard=yes/' "$AVD_CONFIG"
58+
sed -i.bak 's/^hw\.keyboard=.*/hw.keyboard=yes/' "$AVD_CONFIG"
5959
grep -q "^hw.keyboard=" "$AVD_CONFIG" || echo "hw.keyboard=yes" >> "$AVD_CONFIG"
60-
sed "${SED_INPLACE[@]}" 's/^hw\.mainKeys=.*/hw.mainKeys=yes/' "$AVD_CONFIG"
60+
sed -i.bak 's/^hw\.mainKeys=.*/hw.mainKeys=yes/' "$AVD_CONFIG"
6161
grep -q "^hw.mainKeys=" "$AVD_CONFIG" || echo "hw.mainKeys=yes" >> "$AVD_CONFIG"
62+
rm -f "$AVD_CONFIG.bak"
6263
fi
6364

6465
if pgrep -f "emulator.*${AVD_NAME}" > /dev/null 2>&1; then
@@ -68,11 +69,12 @@ if pgrep -f "emulator.*${AVD_NAME}" > /dev/null 2>&1; then
6869
fi
6970

7071
echo "Starting emulator '$AVD_NAME'..."
71-
EMULATOR_ARGS=(-port "$PORT")
72-
if [ "${CI:-}" = "true" ]; then
73-
EMULATOR_ARGS+=(-no-window -no-audio -no-boot-anim -no-snapshot -gpu swiftshader_indirect)
72+
EMULATOR_ARGS=("@${AVD_NAME}" -port "$PORT")
73+
if [ -n "${CI:-}" ]; then
74+
EMULATOR_ARGS+=(-no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim)
7475
fi
75-
emulator "@${AVD_NAME}" "${EMULATOR_ARGS[@]}" > /dev/null 2>&1 &
76+
77+
emulator "${EMULATOR_ARGS[@]}" > /dev/null 2>&1 &
7678

7779
echo "Waiting for emulator ($SERIAL) to connect to ADB..."
7880
if ! timeout 120 adb -s "$SERIAL" wait-for-device; then

0 commit comments

Comments
 (0)