diff --git a/.github/scripts/android-js-fatal.sh b/.github/scripts/android-js-fatal.sh index bfff06a8..a4746ead 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 } @@ -46,7 +53,8 @@ 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 adb install -r "$APK" -adb shell pm clear "$PACKAGE" >/dev/null +# 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 658b79b7..3a8e9944 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 } @@ -80,7 +87,8 @@ case "$INSTALL" in apk) install_apk ;; split) install_split ;; esac -adb shell pm clear "$PACKAGE" >/dev/null +# 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