From 4b392cb4c4ecdd993208bcbec2b2c48129ee8422 Mon Sep 17 00:00:00 2001 From: Logan Date: Thu, 20 Aug 2026 14:35:08 -0400 Subject: [PATCH] fix(android): point the emulator script at the built APK's id The third declaration of the app's identity, and the one #159 did not cash out in: PKG defaulted to "app.yellowjacket" while `make android-install` installs whatever is in bin/, which after `wails3 task android:assemble:apk` is app.yellowjacket.dev. So android-launch, android-logs and android-smoke addressed a package the build had not produced, and the certificate-change message named the wrong id to uninstall -- the release one. It is derived from bin/yellowjacket.apk the same way the tasks are, so it follows whichever variant was built last. YJ_ANDROID_PKG still overrides, and the literal survives only for a tree with no APK yet, where these commands are asking about whatever is already installed and there is nothing to read. cmd_inspect's probe order goes with it: "$PKG.dev" would append a second suffix to an id that already carries one, so the candidates are derived from the resolved id in either direction -- debug sibling first, release second, as before. --- scripts/android-emulator.sh | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/scripts/android-emulator.sh b/scripts/android-emulator.sh index 578528f..025b57c 100755 --- a/scripts/android-emulator.sh +++ b/scripts/android-emulator.sh @@ -34,7 +34,21 @@ cd "$(dirname "$0")/.." AVD="${YJ_AVD:-yj-test}" SDK="${ANDROID_SDK_ROOT:-${ANDROID_HOME:-$HOME/Android/Sdk}}" -PKG="${YJ_ANDROID_PKG:-app.yellowjacket}" +# The third declaration of the app's identity, and the one #159 did not +# cash out in -- but the same hazard, so it is derived rather than +# written down too. The APK in bin/ is what `make android-install` is +# about to install and what `android-launch`, `logs` and `smoke` are +# about to address, so it is the authority; whatever Gradle resolved the +# applicationId to, suffix included, is in the file. +# +# The literal survives only as the answer for a tree with no APK built +# yet, where these commands are asking about whatever is already on the +# device and there is nothing to read. YJ_ANDROID_PKG still overrides. +PKG="${YJ_ANDROID_PKG:-}" +if [ -z "$PKG" ] && [ -f bin/yellowjacket.apk ]; then + PKG="$(./scripts/android-pkgid.sh bin/yellowjacket.apk 2>/dev/null || true)" +fi +PKG="${PKG:-app.yellowjacket}" # Where `make android-inspect` forwards the WebView's devtools socket. CDP_PORT="${YJ_ANDROID_CDP_PORT:-9222}" # **Not "$PKG/.MainActivity".** A leading-dot activity is resolved @@ -281,15 +295,24 @@ cmd_inspect() { need_sdk pick_device || die "no device -- plug a phone in (USB debugging on) or run 'make android-emulator'" - local pkg pid + local pkg pid candidates pid="" - for pkg in "$PKG.dev" "$PKG"; do + # Debug sibling first, release second, whichever way round $PKG was + # resolved -- it is read from the built APK now, so it is already the + # .dev id whenever a debug build is what is in bin/, and appending a + # second ".dev" to it would probe a package that cannot exist. + case "$PKG" in + *.dev) candidates="$PKG ${PKG%.dev}" ;; + *) candidates="$PKG.dev $PKG" ;; + esac + + for pkg in $candidates; do pid=$("$ADB" shell pidof "$pkg" 2>/dev/null | tr -d '\r' | awk '{print $1}') [ -n "$pid" ] && break done - [ -n "$pid" ] || die "neither $PKG.dev nor $PKG is running; launch it first" + [ -n "$pid" ] || die "none of: $candidates is running; launch it first" "$ADB" forward --remove-all >/dev/null 2>&1 || true "$ADB" forward "tcp:$CDP_PORT" "localabstract:webview_devtools_remote_$pid" >/dev/null \