Skip to content

examples: bazel run that boots a hermetic emulator (demo delta) - #5

Closed
AttilaTheFun wants to merge 1 commit into
android-supportfrom
android-example-bazel-run
Closed

examples: bazel run that boots a hermetic emulator (demo delta)#5
AttilaTheFun wants to merge 1 commit into
android-supportfrom
android-example-bazel-run

Conversation

@AttilaTheFun

Copy link
Copy Markdown
Owner

A small demo delta (stacked on the Android PR bazelbuild#1818) showing what it'd take to
make the example runnable with zero external setup — no Android Studio, no device:

bazel run //examples/cross_compilation/android_app:run

It installs the APK on a connected device/emulator and launches it; if nothing is
connected it boots a hermetic emulator first (downloaded emulator + AOSP
system image), so the whole Kotlin → Swift JNI → Swift chain runs from a clean
checkout. Verified end-to-end — booted, installed, launched:

The example launched by bazel run on a freshly-booted hermetic emulator, showing "Hello from Swift, Android!"

The delta (4 files)

  • emulator.bzl — a dev module extension that downloads the emulator + a system
    image (the two pieces @androidsdk doesn't provide; adb comes from @androidsdk).
  • android.MODULE.bazeluse_extension + use_repo for those two repos.
  • run.sh + a sh_binary(name = "run") — boot-if-needed, install, launch.

Caveats (why it's a separate PR, not folded into bazelbuild#1818)

  • macOS/arm64 only — the emulator and image URLs are pinned for darwin_aarch64,
    to keep the delta small. A real version would select() per host OS/arch.
  • Not wired into CI — it boots a GUI emulator and is for local use; the build
    is still covered by app_build_test.
  • Adds a couple of large downloads (emulator + system image) on first bazel run.

Mostly meant to show the shape/cost. Happy to fold it into bazelbuild#1818, generalize it
across platforms, or leave the example build-only — your call.

Adds //examples/cross_compilation/android_app:run, which installs the example
APK on a connected device/emulator and launches it — booting a hermetic
emulator first if nothing is connected, so the example runs with nothing
preinstalled (no Android Studio, no device). adb comes from @AndroidSDK; the
emulator + AOSP system image are downloaded by a dev module extension
(emulator.bzl). macOS/arm64 only, to keep the delta small.

Demonstrates what zero-setup 'bazel run' support would cost for the example.

Claude-Session: https://claude.ai/code/session_01SmG1kqA3qB4WsLGU2xavuJ
@AttilaTheFun

Copy link
Copy Markdown
Owner Author

Folded into the base Android PR (bazelbuild#1818) — keith's fine with including the hermetic emulator example there. The commit is now part of bazelbuild#1818.

@AttilaTheFun
AttilaTheFun deleted the android-example-bazel-run branch July 2, 2026 23:31
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