Skip to content

adb: resolve to known-good binary instead of trusting PATH order#49

Merged
dadachi merged 1 commit intomainfrom
adb-resolve-prefer-android-home
May 3, 2026
Merged

adb: resolve to known-good binary instead of trusting PATH order#49
dadachi merged 1 commit intomainfrom
adb-resolve-prefer-android-home

Conversation

@dadachi
Copy link
Copy Markdown
Contributor

@dadachi dadachi commented May 3, 2026

Summary

Surfaced during the first real Layer 3 visual smoke against a booted Android emulator. The agent's installAndLaunch (#39) and captureScreenshot (#38) were calling adb via PATH, which on this dev machine was ~/.apportable/SDK/bin/adb — an i386 Mach-O from 2014 that fails to exec on Apple Silicon with "spawn Unknown system error -86". Visible adb installs (Android Studio default, /Applications/android-sdk-macosx, Homebrew) were further down PATH and never reached.

Resolution priority

New helper resolveAdbPath() in src/adb.ts:

  1. $ANDROID_HOME/platform-tools/adb
  2. $ANDROID_SDK_ROOT/platform-tools/adb (legacy spelling)
  3. ~/Library/Android/sdk/platform-tools/adb (Android Studio default on macOS)
  4. /Applications/android-sdk-macosx/platform-tools/adb (older standalone install)
  5. /opt/homebrew/bin/adb (Homebrew on Apple Silicon)
  6. /usr/local/bin/adb (Homebrew on Intel)
  7. "adb" (fall back to PATH)

First existing path wins. src/validation/capture.ts (Android branch) and src/validation/launch.ts (install + launch) now use this helper instead of trusting PATH.

Real-mode smoke

On this dev machine, adb now resolves to /Applications/android-sdk-macosx/platform-tools/adb (universal binary). The Apple Silicon spawn error is gone.

Newly-surfaced (separate concern, documented in README)

When multiple Android targets are attached (e.g. physical device + emulator), adb requires ANDROID_SERIAL=<serial> to disambiguate. This is a stock adb feature, not something the agent needs to implement — the agent runs adb directly and inherits the env var. README's "Optional flags" section now documents both the resolution priority and the disambiguator.

Test plan

  • npm run ci — 19/19 green.
  • resolveAdbPath() real-mode lookup returns /Applications/android-sdk-macosx/platform-tools/adb (universal binary) on this machine.
  • captureScreenshot({platform: "android"}) no longer hits the i386 spawn error; surfaces the multi-device disambiguation message cleanly.
  • After merge: re-run NATIVEAPPTEMPLATE_VISUAL=1 npm run dev -- "..." with ANDROID_SERIAL=emulator-5554 to confirm full Android Layer 3 path works.

🤖 Generated with Claude Code

Surfaced during the first real Layer 3 visual smoke against a booted
Android emulator. The agent's installAndLaunch (#39) and
captureScreenshot (#38) were calling `adb` via the PATH-resolved
binary, which on this dev machine was
`~/.apportable/SDK/bin/adb` — an i386 Mach-O from 2014 that fails
to exec on Apple Silicon with "spawn Unknown system error -86".
Visible adb installs (Android Studio default, /Applications/android-
sdk-macosx, Homebrew) were further down PATH and never reached.

New helper resolveAdbPath() in src/adb.ts walks a fixed priority
order: env-var locations first ($ANDROID_HOME, $ANDROID_SDK_ROOT),
then known macOS install paths (Android Studio default, the older
/Applications/android-sdk-macosx, /opt/homebrew, /usr/local), and
falls back to "adb" via PATH. First existing path wins.

src/validation/capture.ts (Android branch) and
src/validation/launch.ts (install + launch) now resolve via this
helper instead of trusting PATH.

Real-mode smoke confirms the fix: on this machine, adb now resolves
to /Applications/android-sdk-macosx/platform-tools/adb (universal
binary, x86_64+arm64). The Apple Silicon spawn error is gone.

Newly-surfaced (separate concern, documented in README): when
multiple Android targets are attached (e.g. physical device +
emulator), adb requires ANDROID_SERIAL=<serial> to disambiguate.
This is a stock adb feature, not something the agent needs to
implement — the agent runs adb directly and inherits the env var.

Tests: 19/19 npm run ci green. (No adb-specific test in CI since
that requires a real Android SDK; resolution logic is verified by
the real-mode smoke output above.)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@dadachi dadachi merged commit 13e822a into main May 3, 2026
1 check passed
@dadachi dadachi deleted the adb-resolve-prefer-android-home branch May 3, 2026 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant