Skip to content

Android (S1): native host (RuneView, lifecycle, insets, back) #2648

Done

Description

@pascalandr

Follow-up to #2484 (slice S1 of the native Android host series on https://github.com/NeuralNomadsAI/rune; builds on S0).

Gap on dev (3e46617e5)

  • crates/rune/src/app.rs:1244: App::try_run has no Android branch; it falls through to the winit path, which requires an AndroidApp.
  • crates/rune/src/platform.rs:12-13: platform::embed (LayerHost) is Apple-only, and its surface cannot be detached and reattached across Android surface lifecycle changes.
  • crates/rune/src/render/device.rs:239-241: an adapter whose only shortfall is max_uniform_buffer_binding_size (16 KB on Android GLES drivers) is asked for wgpu::Limits::default() and fails device creation.

Slice (29 files, +1239 −40 over S0)

  • platform/android/: JNI entry points, pure lifecycle state machine with host tests, stdout/stderr forwarded to logcat.
  • LayerHost accepts an ANativeWindow and supports detaching/reattaching its surface.
  • Kotlin RuneActivity / RuneView (SurfaceView + Choreographer) in crates/rune/android/ and rune::android_main!.
  • Density, system bars and display cutout mapped to Cx::safe_area; soft keyboard as a raised bottom inset (adjustNothing); dark mode; Back mapped to Escape when something has focus.
  • examples/android-hello, scripts/android-run.sh, ANDROID.md, and an apk CI job. winit is not used at runtime on Android and vendor/winit is untouched.

Checked

  • Host: 9 lifecycle tests (surface loss/recreation, 20 background trips, rotation, keyboard inset without resize).
  • CI: both Android checks and the APK build green on the fork.
  • Emulator (x86_64 API 35, GLES): hello renders; same process survives 20 Home/return trips; rotation redraws; dark mode updates arrive; Back returns to launcher.
  • Also verified merged onto current dev (3e46617e5) in android/next (03f8c0ff1).
  • Not checked in S1: physical device, Vulkan (emulator ran GLES), rotation mid-animation (Vulkan + Xiaomi 14 120 Hz checked in later slices).

Reference branch

Questions

  1. winit's Android backend still links (its NativeActivity glue requires an android_main symbol, which Rune defines as a stub). Would you rather cfg winit out of the Android build entirely (~200 files naming winit types)?
  2. Is crates/rune/android/ the right home for the Kotlin sources, and ly.anoma.rune the package name you want?
  3. Runtime::set_safe_area currently carries the keyboard height as part of the bottom inset. Do you want a separate keyboard inset on Cx instead?

Activity

  1. opencodejr commented on Nov 27, 2026

    @opencodejr
    Contributor

    verified all three gaps on dev (crates/rune/src/app.rs, crates/rune/src/platform.rs / platform/embed.rs, and crates/rune/src/render/device.rs). this also builds on s0 (#2647), and all three questions need a maintainer call before s1 lands:

    1. winit on android: winit is referenced in 235 files under crates/rune/src (including pub use winit::raw_window_handle in lib.rs, window/, and overlay/). keeping winit linked with a stub android_main keeps s1 small and avoids touching 200+ files until winit is decoupled more broadly (shared with iOS: an app starts with rune::run and draws in a RuneView (first slice of M6) #803 and Compile for wasm32-wasip2: wasm32 is treated as "browser", and winit has no WASI platform #911), at the cost of pulling winit/android-activity into android builds.
    2. kotlin source layout and package name: there is no existing kotlin/java directory in the repo, and jni entry points bake the package name into the abi. existing reverse-dns ids in the repo use dev.rune.* (credentials/secret_service.rs, tray.rs), whereas ly.anoma.rune does not appear anywhere in the repo.
    3. keyboard height in Cx::safe_area vs a separate inset: Cx::safe_area (runtime/cx.rs) also feeds El::on_edge_drag (runtime/input/edge_drag.rs), so adding keyboard height to safe_area[2] expands bottom edge-drag bands by the keyboard height and mixes hardware bars/cutouts with transient ime overlap. on web (platform/web/platform.js, platform/web/input.rs, runtime/selection/caret.rs), rune already keeps safe_area separate from the keyboard (visual_viewport_y for automatic caret reveal). a separate keyboard inset on Cx matches android WindowInsets (systemBars/displayCutout vs ime), ios (safeAreaInsets vs keyboardLayoutGuide), and css (env(safe-area-inset-*) vs VirtualKeyboard), whereas folding it into safe_area[2] lifts views that only pad by Cx::safe_area.

    questions for maintainers:

    • should s1 keep winit linked with a stub android_main (deferring the ~235-file cfg split), and should kotlin host sources live in crates/rune/android/ under dev.rune or ly.anoma.rune?
    • should soft-keyboard overlap stay out of Cx::safe_area behind a separate Cx keyboard inset (matching web's safe_area / visual_viewport_y split and keeping on_edge_drag unaffected), or fold into safe_area[2]?
  2. pascalandr commented on Nov 27, 2026

    @pascalandr
    Author
    1. winit: the fork keeps it linked and cfgs nothing out but rune::run; rune::android_main! exports the entry RuneView calls. No stub android_main was needed.
    2. Package: ly.anoma.rune has no reason behind it. dev.rune is fine; the rename is mechanical (Kotlin package, JNI symbol names, the manifest meta-data key) and the fork will follow whatever is chosen.
    3. Keyboard: the fork folds the IME inset into safe_area[2] and passes the band the keyboard leaves in sight through set_visual_viewport_y, the web's hook, for the caret reveal. The edge-drag point is right, and a separate keyboard inset on Cx is the better shape: safe_area would be bars and cutout only, and an app that wants its last field to clear the keyboard pads by the keyboard inset too. The fork will move to it once it exists.
  3. Hona commented on Nov 28, 2026

    @Hona
    Member

    Shipped Android S1 native host in PR #2689 (commit 2f15e4a90).

    Design decisions

    • Separate keyboard inset (Cx::keyboard_inset() / Runtime::set_keyboard_inset()): Soft-keyboard overlap stays separate from Cx::safe_area() (hardware bars and display cutouts) so El::on_edge_drag bands are unaffected, while views can pad by cx.safe_area()[2].max(cx.keyboard_inset()) and focused text fields auto-scroll above the keyboard without resizing the layout viewport (adjustNothing).
    • Kotlin host package & layout: dev.rune (RuneActivity and RuneView) under crates/rune/android/src/main/java/dev/rune/, using framework Android APIs (no AndroidX dependency).
    • Bypass winit at runtime, keep linked for now: App::try_run routes to platform::android::run on Android while leaving vendor/winit untouched; rune::android_main! exports JNI_OnLoad and binds RuneView methods with RegisterNatives.
    • Detachable LayerHost + Android GLES limits: Extended rune::embed::LayerHost to Android ANativeWindow with detach_surface / attach_native_window, enabled wgpu/gles alongside Vulkan on Android, and fell back to wgpu::Limits::downlevel_defaults() for adapters limited to 16 KiB uniform buffer bindings.

    Verification

    • Verified locally (Windows): cargo check -p rune -p android-hello, cargo check --target wasm32-unknown-unknown -p rune, 8 host lifecycle tests (platform::android::machine_tests covering surface loss/recreation, 20 Home/return trips, rotation, keyboard inset without resize, dark mode, Back, Choreographer deduplication), required_device_limits test, keyboard_inset edge-drag isolation and caret-reveal tests, and android-hello unit test.
    • Verified on GitHub Actions CI: android (aarch64-linux-android, x86_64-linux-android, and full NDK link + Kotlin compile + debug APK packaging of examples/android-hello), check, and size all passed.
    • Not run locally: Android emulator or physical Android device runtime. Please reopen or file a follow-up if anything behaves unexpectedly on device or emulator.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions