Skip to content

Commit 998d8e2

Browse files
committed
Stabilize instrumentation boot and dependency injection
1 parent ea440c5 commit 998d8e2

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

scripts/build-android-app.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,31 @@ wait_for_emulator() {
449449
return 0
450450
}
451451

452+
wait_for_package_service() {
453+
local serial="$1"
454+
local timeout="${PACKAGE_SERVICE_TIMEOUT:-120}"
455+
if ! [[ "$timeout" =~ ^[0-9]+$ ]] || [ "$timeout" -le 0 ]; then
456+
timeout=120
457+
fi
458+
local deadline=$((SECONDS + timeout))
459+
local last_log=$SECONDS
460+
while [ $SECONDS -lt $deadline ]; do
461+
if "$ADB_BIN" -s "$serial" shell cmd package list packages >/dev/null 2>&1; then
462+
return 0
463+
fi
464+
if "$ADB_BIN" -s "$serial" shell pm list packages >/dev/null 2>&1; then
465+
return 0
466+
fi
467+
if [ $((SECONDS - last_log)) -ge 10 ]; then
468+
ba_log "Waiting for package manager service on $serial"
469+
last_log=$SECONDS
470+
fi
471+
sleep 2
472+
done
473+
ba_log "Package manager service not ready on $serial after ${timeout}s" >&2
474+
return 1
475+
}
476+
452477
stop_emulator() {
453478
if [ -n "${EMULATOR_SERIAL:-}" ]; then
454479
"$ADB_BIN" -s "$EMULATOR_SERIAL" emu kill >/dev/null 2>&1 || true
@@ -556,6 +581,11 @@ if ! wait_for_emulator "$EMULATOR_SERIAL"; then
556581
exit 1
557582
fi
558583

584+
if ! wait_for_package_service "$EMULATOR_SERIAL"; then
585+
stop_emulator
586+
exit 1
587+
fi
588+
559589
UI_TEST_TIMEOUT_SECONDS="${UI_TEST_TIMEOUT_SECONDS:-900}"
560590
if ! [[ "$UI_TEST_TIMEOUT_SECONDS" =~ ^[0-9]+$ ]] || [ "$UI_TEST_TIMEOUT_SECONDS" -le 0 ]; then
561591
ba_log "Invalid UI_TEST_TIMEOUT_SECONDS=$UI_TEST_TIMEOUT_SECONDS provided; falling back to 900"

scripts/update_android_ui_test_gradle.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,22 @@ def _has_dependency(block: str, coordinate: str) -> bool:
173173
)
174174

175175
def _find_dependencies_block(self) -> tuple[int, int] | None:
176+
preferred: tuple[int, int] | None = None
177+
fallback: tuple[int, int] | None = None
176178
for name, start, end, parents in self._iter_blocks():
177179
if name != "dependencies":
178180
continue
179181
if parents and parents[-1] in {"buildscript", "pluginManagement"}:
180182
continue
181-
return start, end
182-
return None
183+
block_content = self.content[start:end]
184+
if re.search(r"^\s*(implementation|api|compile|androidTestImplementation|androidTestCompile)\b", block_content, re.MULTILINE):
185+
preferred = (start, end)
186+
break
187+
if "classpath" in block_content and not re.search(r"^\s*(implementation|api|compile)\b", block_content, re.MULTILINE):
188+
continue
189+
if fallback is None:
190+
fallback = (start, end)
191+
return preferred or fallback
183192

184193
def _append_dependencies_block(self) -> None:
185194
if not self.content.endswith("\n"):

0 commit comments

Comments
 (0)