Repository navigation
feat(mobile): add an Android emulator harness for device-only repros - #13366
makoto-developer wants to merge 3 commits into
Conversation
Mobile bugs that only appear under an Android IME keep stalling on "no Android device here": stablyai#7427 sat unreproduced with the reporter's trace unverified, and stablyai#7495 needed a hand-built emulator rig before it could be closed. `start:emulator` only drives the iOS simulator, and the only other Android script packages a release, so every contributor rebuilds the same setup from scratch. Add `pnpm start:emulator:android`, which boots or reuses an AVD, waits for sys.boot_completed, reverses the Metro and mock-host ports, and prints the exact next commands. Path and output parsing live in a separate module so the parts that silently go wrong are unit-tested rather than discovered on a cold machine: - AVDs are resolved the way avdmanager writes them ($XDG_CONFIG_HOME/.android), and that path is passed to every tool the script spawns. Reporting it is not enough — the emulator reads its own env, so `-list-avds` otherwise comes back empty for an AVD that was just created. - adb output is only trusted when a device reports `device`, so a still-booting emulator and a physical handset are both skipped. - JAVA_HOME is checked against the range the Android Gradle plugin accepts. JDK 24+ aborts configureCMakeDebug with a restricted-method error that reads like an unrelated native build failure. An explicitly requested --avd is no longer ignored when a different AVD is already running; the script says which one to stop. README gains the prerequisites and the four traps that cost the most time: the build JDK, the Play Store image Gboard needs for CJK input, the AVD path, and the mock host colliding with a running Orca desktop on 6768.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds cross-platform Android SDK, AVD, tool, emulator, and Java environment helpers with Vitest coverage. Adds a TypeScript command that validates tools, selects or starts an AVD, waits for boot completion, reverses development ports, and prints follow-up commands. Adds the Mergeability Score: ⚪ Minimal · up to This PR adds a localized Android emulator helper for developer workflows without changing shipped application behavior; no actionable merge-blocking risk remains after normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (3)
mobile/scripts/android-emulator-environment.ts (1)
1-3: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueShorten this file-level comment.
The file name and exports already state this responsibility. Keep only non-obvious rationale in one short line.
As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.”
Source: Coding guidelines
mobile/src/android-emulator-environment.test.ts (1)
26-49: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove redundant Given/When/Then comments.
The test names and assertions already identify setup, action, and expected result. Keep comments only where they add non-obvious platform or emulator behavior.
As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.”
Also applies to: 53-60, 63-83, 86-100, 102-165
Source: Coding guidelines
mobile/scripts/start-android-emulator.ts (1)
2-4: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueShorten this file-level comment.
The command name states the workflow. Keep only the non-obvious emulator limitation in one short line.
As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line; do not explain obvious behavior or walk through code.”
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 3bd48262-d45b-40ad-84d3-0240f5f22b51
📒 Files selected for processing (5)
mobile/README.mdmobile/package.jsonmobile/scripts/android-emulator-environment.tsmobile/scripts/start-android-emulator.tsmobile/src/android-emulator-environment.test.ts
Review findings from the first revision: - ANDROID_EMULATOR_HOME was ignored. `emulator -help-environment` documents it as the replacement for ~/.android, so it belongs between ANDROID_AVD_HOME and the XDG fallback. - Reuse compared the running AVD with a strict equality while startup matches case-insensitively on a substring, so `--avd pixel` rejected the very Pixel_7_API_36 it would otherwise have booted. Both paths now share the rule. - A failed `adb reverse` was still listed as reversed. Successful and failed ports are now reported separately. - The README pinned arm64-v8a, which on an Intel or AMD host runs under translation with no hardware acceleration. Select the ABI for the host CPU. - The 6768 workaround told the reader to move the mock host without mentioning that the new port has to be reversed too.
|
All five findings were valid; fixed in
Re-exercised on the emulator: reuse with a partial |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d7ced9ae-3fa5-4d40-8c0b-32b74fc740fa
📒 Files selected for processing (4)
mobile/README.mdmobile/scripts/android-emulator-environment.tsmobile/scripts/start-android-emulator.tsmobile/src/android-emulator-environment.test.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- mobile/src/android-emulator-environment.test.ts
- mobile/scripts/start-android-emulator.ts
- mobile/scripts/android-emulator-environment.ts
…ness An exported-but-empty ANDROID_EMULATOR_HOME or ANDROID_USER_HOME passed the nullish check, so path.join resolved the AVD store to the relative './avd' and every tool in the harness was pointed at a directory that does not exist. Match the truthiness checks the rest of the module already uses.
Summary
Adds
pnpm start:emulator:android, so an Android repro is one command instead of an afternoon.Mobile bugs that only appear under an Android IME keep stalling on "no Android device here":
cannot_repro(env blocked)."start:emulatordrives the iOS simulator only (--device 'iPhone 17 Pro'), and the sole other Android script packages a release, so every contributor rebuilds the same setup from scratch. I just did, while chasing #7427 on Android, and this is that setup with the traps encoded.The script boots or reuses an AVD, waits for
sys.boot_completed, reverses the Metro and mock-host ports, and prints the exact next commands. Flags:--avd <name>,--port <n>(repeatable),--no-reverse.What is unit-tested rather than discovered on a cold machine. Path and output parsing live in
android-emulator-environment.tsso the parts that go wrong silently are pinned:avdmanagerwrites them ($XDG_CONFIG_HOME/.android/avd), and that path is passed to every spawned tool. Reporting it is not enough — the emulator reads its own env, so-list-avdsotherwise returns nothing for an AVD that was just created. I shipped this bug into my own first draft and only caught it by running the script.device, so a still-booting emulator (offline) and a physical handset are both skipped.JAVA_HOMEis checked against the range AGP accepts. JDK 24+ abortsconfigureCMakeDebugwith a restricted-method error that reads like an unrelated native failure.--avdis no longer ignored when a different AVD is already running; the script names the one to stop.README gains the prerequisites and the four traps that cost the most time: the build JDK, the Play Store image Gboard needs for CJK input, the AVD path, and the mock host colliding with a running Orca desktop on 6768.
Screenshots
No visual change — this is developer tooling.
Testing
pnpm lint(mobileoxlint, clean)pnpm typecheck(tsc --noEmitinmobile/)pnpm test—mobile3401 passed, 11 of them new. One pre-existing unrelated failure,src/mock-server-key-pair.test.ts > makes concurrent creators converge on the persisted winner, which fails identically on an unmodified tree.pnpm build— not run; adds a dev script and its tests, no app code.Exercised end to end on macOS 15 / Apple silicon against a Pixel 7 API 36 AVD: cold boot, reuse of a running emulator,
--avdmatch and mismatch, missing AVD, and the JDK 17 (silent) and JDK 25 (warned) branches.AI Review Report
Reviewed with Claude.
%LOCALAPPDATA%\Android\Sdk,~/Library/Android/sdk,~/Android/Sdk), tool paths get.exefor the native binaries and.batfor theavdmanagerwrapper, and every path is built withpath.join. The review caught a${JAVA_HOME}/bin/javatemplate literal that would have broken on Windows; it now usespath.joinandjava.exe. All three platform branches are asserted in tests. Only macOS was exercised for real — Linux and Windows rest on the unit tests, which is the honest limit here.--avdbeing silently ignored when any emulator was already up. Both fixed and covered.package.jsonscript. Nothing here executes during a build or in the shipped app.adbevery 2s with a 5-minute ceiling; no busy loop.unref'd on purpose, so the script exits while the emulator keeps running — that is the intended workflow, and the serial is printed so it can be killed withadb emu kill.Security Audit
Reviewed with Claude.
execFile/spawnonly, never a shell, so no interpolation reaches a command line. Executable paths are derived fromANDROID_HOMEor a platform default and areexistsSync-checked before use.--avdand--portare compared and range-checked, not interpolated into commands; ports must be positive integers.process.envplus two Android path variables. No secrets are read, written, or logged; the script prints only paths, an AVD name and a device serial.adb reversemaps loopback ports into the emulator the same wayexpo run:androidalready does. It opens nothing to the network.Notes
MAX_SUPPORTED_BUILD_JDK). It is a warning, never a hard stop, so a future AGP that supports newer JDKs makes it stale rather than wrong.mobile/scripts/mock-server-terminal-stream.tsanswersterminal.sendwith{ ok: true }while the client gates onaccepted, so mock-based runs silently drop the carriage return after a flushed IME composition. That fix is in fix(mobile): hold the Japanese IME reading off the terminal until it commits #13070 rather than here, to keep this PR to tooling.