From d8843e493b9b19a3dabc3522dc3e45e6f0d0c92c Mon Sep 17 00:00:00 2001 From: Kishan P Rao Date: Wed, 14 Oct 2026 11:11:18 +0200 Subject: [PATCH 1/2] ci: fix the flaky app launch in the android emulator tests --- .github/scripts/android-js-fatal.sh | 16 ++++++++++++---- .github/scripts/android-native-crash.sh | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.github/scripts/android-js-fatal.sh b/.github/scripts/android-js-fatal.sh index bfff06a8..67b1a3fb 100644 --- a/.github/scripts/android-js-fatal.sh +++ b/.github/scripts/android-js-fatal.sh @@ -20,7 +20,7 @@ FORWARD_BOUND_S=7 EXIT_BOUND_S=2 wait_for_log() { - local pattern="$1" deadline="$2" + local pattern="$1" deadline="$2" uid for _ in $(seq 1 "$deadline"); do if adb logcat -d | grep -qE "$pattern"; then return 0 @@ -29,7 +29,14 @@ wait_for_log() { done echo "::error::timed out after ${deadline}s waiting for: $pattern" - adb logcat -d | tail -50 + if ! adb shell pidof "$PACKAGE" >/dev/null 2>&1; then + echo "$PACKAGE is not running" + fi + adb logcat -d -s ActivityManager:I ActivityTaskManager:I | grep -F "$PACKAGE" | tail -20 || true + uid="$(adb shell pm list packages -U "$PACKAGE" | tr -d '\r' | sed -n "s/^package:$PACKAGE uid://p")" + if [ -n "$uid" ]; then + adb logcat -d --uid="$uid" | tail -50 + fi return 1 } @@ -44,9 +51,10 @@ at_most() { trap 'adb logcat -d -v epoch > "$LOGCAT_OUT" 2>/dev/null || true' EXIT adb wait-for-device -adb uninstall "$PACKAGE" >/dev/null 2>&1 || true +if adb shell pm path "$PACKAGE" >/dev/null 2>&1; then + adb uninstall "$PACKAGE" +fi adb install -r "$APK" -adb shell pm clear "$PACKAGE" >/dev/null adb logcat -c adb shell am start -n "$ACTIVITY" >/dev/null diff --git a/.github/scripts/android-native-crash.sh b/.github/scripts/android-native-crash.sh index 658b79b7..72478028 100755 --- a/.github/scripts/android-native-crash.sh +++ b/.github/scripts/android-native-crash.sh @@ -25,7 +25,7 @@ case "$INSTALL" in esac wait_for_log() { - local pattern="$1" deadline="$2" + local pattern="$1" deadline="$2" uid for _ in $(seq 1 "$deadline"); do if adb logcat -d | grep -qE "$pattern"; then return 0 @@ -34,7 +34,14 @@ wait_for_log() { done echo "::error::timed out after ${deadline}s waiting for: $pattern" - adb logcat -d | tail -50 + if ! adb shell pidof "$PACKAGE" >/dev/null 2>&1; then + echo "$PACKAGE is not running" + fi + adb logcat -d -s ActivityManager:I ActivityTaskManager:I | grep -F "$PACKAGE" | tail -20 || true + uid="$(adb shell pm list packages -U "$PACKAGE" | tr -d '\r' | sed -n "s/^package:$PACKAGE uid://p")" + if [ -n "$uid" ]; then + adb logcat -d --uid="$uid" | tail -50 + fi return 1 } @@ -75,12 +82,13 @@ ABI="$(adb shell getprop ro.product.cpu.abi | tr -d '\r')" ABI_US="${ABI//-/_}" echo "install mode: $INSTALL, device abi: $ABI, device abis: $(adb shell getprop ro.product.cpu.abilist | tr -d '\r')" -adb uninstall "$PACKAGE" >/dev/null 2>&1 || true +if adb shell pm path "$PACKAGE" >/dev/null 2>&1; then + adb uninstall "$PACKAGE" +fi case "$INSTALL" in apk) install_apk ;; split) install_split ;; esac -adb shell pm clear "$PACKAGE" >/dev/null adb logcat -c trap 'adb logcat -d > "$LOGCAT_OUT" 2>/dev/null || true; rm -rf "$WORK"' EXIT From 31b278d85a2f1b68a21a6ae7cf7833ca31c2bc6b Mon Sep 17 00:00:00 2001 From: Kishan P Rao Date: Wed, 14 Oct 2026 11:50:05 +0200 Subject: [PATCH 2/2] ci: wipe the app data with run-as after install --- .github/scripts/android-js-fatal.sh | 6 +++--- .github/scripts/android-native-crash.sh | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/scripts/android-js-fatal.sh b/.github/scripts/android-js-fatal.sh index 67b1a3fb..a4746ead 100644 --- a/.github/scripts/android-js-fatal.sh +++ b/.github/scripts/android-js-fatal.sh @@ -51,10 +51,10 @@ at_most() { trap 'adb logcat -d -v epoch > "$LOGCAT_OUT" 2>/dev/null || true' EXIT adb wait-for-device -if adb shell pm path "$PACKAGE" >/dev/null 2>&1; then - adb uninstall "$PACKAGE" -fi +adb uninstall "$PACKAGE" >/dev/null 2>&1 || true adb install -r "$APK" +# Not pm clear, its late force-stop kills the launch. Uninstall alone can leave data on the cached emulator image. +adb shell run-as "$PACKAGE" find . -mindepth 1 -delete >/dev/null adb logcat -c adb shell am start -n "$ACTIVITY" >/dev/null diff --git a/.github/scripts/android-native-crash.sh b/.github/scripts/android-native-crash.sh index 72478028..3a8e9944 100755 --- a/.github/scripts/android-native-crash.sh +++ b/.github/scripts/android-native-crash.sh @@ -82,13 +82,13 @@ ABI="$(adb shell getprop ro.product.cpu.abi | tr -d '\r')" ABI_US="${ABI//-/_}" echo "install mode: $INSTALL, device abi: $ABI, device abis: $(adb shell getprop ro.product.cpu.abilist | tr -d '\r')" -if adb shell pm path "$PACKAGE" >/dev/null 2>&1; then - adb uninstall "$PACKAGE" -fi +adb uninstall "$PACKAGE" >/dev/null 2>&1 || true case "$INSTALL" in apk) install_apk ;; split) install_split ;; esac +# Not pm clear, its late force-stop kills the launch. Uninstall alone can leave data on the cached emulator image. +adb shell run-as "$PACKAGE" find . -mindepth 1 -delete >/dev/null adb logcat -c trap 'adb logcat -d > "$LOGCAT_OUT" 2>/dev/null || true; rm -rf "$WORK"' EXIT