Skip to content

Commit 1ffcd38

Browse files
authored
Fix crash in emulator launch in android-emulator-tests.sh (#223)
* Wait briefly before starting to poll the emulator in android-emulator-tests.sh * Poll emulator with adb shell getprop sys.boot_completed and manually handle timeout * Remove unused workflow * Update adb check for sys.boot_completed * Update adb check for sys.boot_completed * Update adb check for sys.boot_completed * Update adb check for sys.boot_completed * Syntax cleanup in android-emulator-tests.sh
1 parent 9286ad9 commit 1ffcd38

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

.github/workflows/scripts/android/android-emulator-tests.sh

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,25 @@ log "Starting Android emulator"
9595
# launch the emulator in the background
9696
nohup emulator -no-metrics -partition-size 1024 -memory 4096 -wipe-data -no-window -no-snapshot -noaudio -no-boot-anim -avd "${ANDROID_EMULATOR_NAME}" &
9797

98-
log "Waiting for Android emulator startup"
99-
adb start-server
100-
sleep 5
101-
timeout "${ANDROID_EMULATOR_TIMEOUT}" adb wait-for-any-device
98+
EMULATOR_CHECK_SECONDS_ELAPSED=0
99+
EMULATOR_CHECK_INTERVAL=5 # Seconds between status checks
100+
while true; do
101+
sleep "$EMULATOR_CHECK_INTERVAL"
102+
((EMULATOR_CHECK_SECONDS_ELAPSED+=EMULATOR_CHECK_INTERVAL))
103+
log "Waiting for Android emulator startup ($EMULATOR_CHECK_SECONDS_ELAPSED)"
104+
105+
# Check if the boot is completed
106+
# 'adb shell getprop sys.boot_completed' returns 1 when done
107+
# Ignore failure status since it will fail with "adb: device offline"
108+
BOOT_STATUS=$(adb shell getprop sys.boot_completed || true 2>/dev/null | tr -d '\r')
109+
110+
if [ "$BOOT_STATUS" == "1" ]; then
111+
log "Emulator is ready"
112+
break;
113+
elif [ "$EMULATOR_CHECK_SECONDS_ELAPSED" -ge "$ANDROID_EMULATOR_TIMEOUT" ]; then
114+
fatal "Timeout reached ($ANDROID_EMULATOR_TIMEOUT seconds). Aborting."
115+
fi
116+
done
102117

103118
log "Prepare Swift test package"
104119
# create a staging folder where we copy the test executable

0 commit comments

Comments
 (0)