YrXtals/scripts/android/debug.sh

56 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# installs the apk, launches the activity, and tails logcat filtered to YrXtals and native crash channels.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/_env.sh"
# _env.sh enables `set -e`; turn it off so a single non-zero adb call doesn't kill the script.
set +e
set -u
set -o pipefail
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
"$SCRIPT_DIR/install.sh" release-debug
install_rc=$?
if [[ $install_rc -ne 0 ]]; then
echo "install failed with rc=$install_rc" >&2
exit $install_rc
fi
if [[ -z "${ANDROID_TARGET:-}" ]]; then
echo "no device selected." >&2
exit 2
fi
PKG="org.elseif.yrxtals"
echo "→ adb logcat -c (clear)"
adb -s "$ANDROID_TARGET" logcat -c >/dev/null 2>&1
echo "→ adb shell am force-stop $PKG"
adb -s "$ANDROID_TARGET" shell am force-stop "$PKG" >/dev/null 2>&1
echo "→ adb shell am start -n $PKG/.MainActivity"
adb -s "$ANDROID_TARGET" shell am start -n "$PKG/.MainActivity"
start_rc=$?
echo "am start rc=$start_rc"
# poll up to 5s for the pid; pidof races the activity start.
PID=""
for _ in 1 2 3 4 5 6 7 8 9 10; do
PID="$(adb -s "$ANDROID_TARGET" shell pidof "$PKG" 2>/dev/null | tr -d '\r')"
[[ -n "$PID" ]] && break
sleep 0.5
done
echo "running pid='$PID' on $ANDROID_TARGET — tailing logcat (Ctrl+C to stop)"
# tags: YrXtals (kotlin), yr_crystals + yr_crystals.io (rust + stdio redirect), crash channels.
FILTER=( YrXtals:V yr_crystals:V yr_crystals.io:V AndroidRuntime:E libc:F DEBUG:F '*:S' )
if [[ -n "$PID" ]]; then
exec adb -s "$ANDROID_TARGET" logcat --pid="$PID" "${FILTER[@]}"
else
echo "pidof returned empty; tailing unfiltered by pid" >&2
exec adb -s "$ANDROID_TARGET" logcat "${FILTER[@]}"
fi