Skip to content

Commit 76357f3

Browse files
committed
Stabilize headless ARM emulator startup for UI tests
1 parent c9d5101 commit 76357f3

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

scripts/build-android-app.sh

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ install_android_packages() {
706706
"platform-tools" \
707707
"emulator" \
708708
"platforms;android-35" \
709-
"system-images;android-35;google_apis;x86_64" >/dev/null 2>&1 || true
709+
"system-images;android-35;google_apis;arm64-v8a" >/dev/null 2>&1 || true
710710
}
711711

712712
create_avd() {
@@ -721,16 +721,9 @@ create_avd() {
721721
mkdir -p "$avd_dir"
722722
local ini_file="$avd_dir/$name.ini"
723723
local image_dir="$avd_dir/$name.avd"
724-
if [ -f "$ini_file" ] && [ -d "$image_dir" ]; then
725-
if grep -F -q "$image" "$ini_file" 2>/dev/null; then
726-
ba_log "Reusing existing Android Virtual Device $name"
727-
configure_avd "$avd_dir" "$name"
728-
return
729-
fi
730-
ba_log "Existing Android Virtual Device $name uses a different system image; recreating"
731-
rm -f "$ini_file"
732-
rm -rf "$image_dir"
733-
fi
724+
ANDROID_AVD_HOME="$avd_dir" "$manager" delete avd -n "$name" >/dev/null 2>&1 || true
725+
rm -f "$ini_file"
726+
rm -rf "$image_dir"
734727
if ! ANDROID_AVD_HOME="$avd_dir" "$manager" create avd -n "$name" -k "$image" --device "pixel_5" --force >/dev/null <<<'no'
735728
then
736729
ba_log "Failed to create Android Virtual Device $name using image $image" >&2
@@ -762,6 +755,8 @@ configure_avd() {
762755
["hw.audioInput"]=no
763756
["hw.audioOutput"]=no
764757
["hw.cpu.ncore"]=2
758+
["hw.cpu.arch"]="arm64"
759+
["abi.type"]="arm64-v8a"
765760
)
766761
local key value
767762
for key in "${!settings[@]}"; do
@@ -942,7 +937,7 @@ adb_framework_ready_once() {
942937
local last_log=$SECONDS
943938

944939
while [ $SECONDS -lt $deadline ]; do
945-
local boot_ok dev_boot system_pid pm_ok activity_ok service_ok user_ready service_status cmd_ok
940+
local boot_ok dev_boot system_pid pm_ok activity_ok service_ok user_ready service_status cmd_ok resolve_ok
946941
boot_ok="$($ADB_BIN -s "$serial" shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')"
947942
dev_boot="$($ADB_BIN -s "$serial" shell getprop dev.bootcomplete 2>/dev/null | tr -d '\r')"
948943
system_pid="$(run_with_timeout "$per_try" "$ADB_BIN" -s "$serial" shell pidof system_server 2>/dev/null | tr -d '\r' || true)"
@@ -963,20 +958,26 @@ adb_framework_ready_once() {
963958
if run_with_timeout "$per_try" "$ADB_BIN" -s "$serial" shell cmd -l >/dev/null 2>&1; then
964959
cmd_ok=1
965960
fi
961+
resolve_ok=0
962+
if run_with_timeout "$per_try" "$ADB_BIN" -s "$serial" shell \
963+
"cmd package resolve-activity --brief android.intent.action.MAIN -c android.intent.category.HOME" >/dev/null 2>&1; then
964+
resolve_ok=1
965+
fi
966966
service_status="$(run_with_timeout "$per_try" "$ADB_BIN" -s "$serial" shell service check package 2>/dev/null | tr -d '\r' || true)"
967967
if [ -n "$service_status" ] && printf '%s' "$service_status" | grep -q "found"; then
968968
service_ok=1
969969
fi
970970

971971
if [ "$boot_ok" = "1" ] && [ "$dev_boot" = "1" ] && [ -n "$system_pid" ] \
972972
&& [ $pm_ok -eq 1 ] && [ $activity_ok -eq 1 ] && [ $service_ok -eq 1 ] \
973+
&& [ $resolve_ok -eq 1 ] \
973974
&& [ $cmd_ok -eq 1 ] && [ $user_ready -eq 1 ]; then
974975
ba_log "Android framework ready on $serial (system_server=$system_pid)"
975976
return 0
976977
fi
977978

978979
if [ $((SECONDS - last_log)) -ge $log_interval ]; then
979-
ba_log "Waiting for Android framework on $serial (system_server=${system_pid:-down} boot_ok=${boot_ok:-?}/${dev_boot:-?} pm_ready=$pm_ok activity_ready=$activity_ok cmd_ready=$cmd_ok package_service_ready=$service_ok user_ready=$user_ready)"
980+
ba_log "Waiting for Android framework on $serial (system_server=${system_pid:-down} boot_ok=${boot_ok:-?}/${dev_boot:-?} pm_ready=$pm_ok activity_ready=$activity_ok cmd_ready=$cmd_ok package_service_ready=$service_ok resolve_ready=$resolve_ok user_ready=$user_ready)"
980981
last_log=$SECONDS
981982
fi
982983
sleep 2
@@ -1133,7 +1134,7 @@ if [ ! -x "$EMULATOR_BIN" ]; then
11331134
fi
11341135

11351136
AVD_NAME="cn1UiTestAvd"
1136-
SYSTEM_IMAGE="system-images;android-35;google_apis;x86_64"
1137+
SYSTEM_IMAGE="system-images;android-35;google_apis;arm64-v8a"
11371138
AVD_CACHE_ROOT="${AVD_CACHE_ROOT:-${RUNNER_TEMP:-$HOME}/cn1-android-avd}"
11381139
mkdir -p "$AVD_CACHE_ROOT"
11391140
AVD_HOME="$AVD_CACHE_ROOT"
@@ -1160,7 +1161,7 @@ ANDROID_AVD_HOME="$AVD_HOME" "$EMULATOR_BIN" -avd "$AVD_NAME" -port "$EMULATOR_P
11601161
-gpu swiftshader_indirect -no-audio -no-boot-anim \
11611162
-accel off -no-metrics -camera-back none -camera-front none -skip-adb-auth \
11621163
-feature -Vulkan -netfast -skin 1080x1920 -memory 2048 -cores 2 \
1163-
-writable-system -selinux permissive >"$EMULATOR_LOG" 2>&1 &
1164+
-writable-system -selinux permissive -partition-size 2048 >"$EMULATOR_LOG" 2>&1 &
11641165
EMULATOR_PID=$!
11651166
trap stop_emulator EXIT
11661167

@@ -1348,11 +1349,11 @@ adb_install_file_path() {
13481349
continue
13491350
fi
13501351

1351-
if "$ADB_BIN" -s "$serial" shell pm install -r -t -g "$remote_tmp"; then
1352+
if "$ADB_BIN" -s "$serial" shell pm install -r -t -d -g "$remote_tmp"; then
13521353
install_status=0
13531354
else
13541355
apk_size=$(stat -c%s "$apk" 2>/dev/null || wc -c <"$apk")
1355-
if [ -n "$apk_size" ] && "$ADB_BIN" -s "$serial" shell "cat '$remote_tmp' | pm install -r -t -g -S $apk_size"; then
1356+
if [ -n "$apk_size" ] && "$ADB_BIN" -s "$serial" shell "cat '$remote_tmp' | pm install -r -t -d -g -S $apk_size"; then
13561357
install_status=0
13571358
fi
13581359
fi

0 commit comments

Comments
 (0)