Skip to content

Android (Native Port)

Android: genuinely native port (no Capacitor/WebView)

Section titled “Android: genuinely native port (no Capacitor/WebView)”

The mobile path is native — the same winit+wgpu Rust stack plus embedded libnode, no browser shell.

  • Shell: packages/android-shell — a cdylib (libdowndraft_android.so) implementing android.app.NativeActivity via android-activity. It statically links downdraft-platform (so the winit loop on the app thread and the JS thread share the same event-queue statics — JS dlopens this .so, never a separate platform lib), extracts assets/bundle/ → internalDataPath/bundle/ via manifest.txt (AAssetDir cannot enumerate subdirs), redirects stdio→logcat (tag downdraft), then runs node::Start on bundle/index.js from a spawned thread.
  • libnode: packages/node-mobile — an overlay recipe (pinned node-version.txt + sha256 + patches/ series + overlay/ files) applied to pristine upstream Node v26.10.0; packages/node-mobile/scripts/build-android.mjs produces build/dist/android/<abi>/libnode.so for arm64-v8a/x86_64. NDK r30 required — r28’s clang 19 can’t compile V8 14.6’s consteval regexp dispatch (needs clang ≥20); deps/v8/include/atomic-ref-shim.h polyfills std::atomic_ref for NDKs ≤r28 whose libc++ strips it (no-op on r30), plus g++ host toolset for V8’s C++20 alias-CTAD. --v8-disable-temporal-support is set (vendored Temporal Rust has no Android wiring). NODEJS_MOBILE_FLAVOR=lite builds a smaller libnode (--with-intl=none --without-amaro --without-inspector --without-sqlite, ~17MB smaller binary, ~50MB lower PSS) into build/dist/android-lite/<abi>/ — the engine degrades gracefully (sqlite→in-memory import cache, inspector→no CDP devtools, no Intl.*).
  • Packaging: draft release --target=android → packages/cli/scripts/package-mobile.mjs — Bun-bundles the entry + workers as .mjs files under assets/bundle/ (repo-rel layout, index.js shim), stages dd-assets/ + node_modules/koffi + @koromix/koffi-android-*, writes manifest.txt, then assembles the APK directly with aapt2/zip/zipalign/apksigner (hasCode=false — no Gradle/dex needed). packages/android-shell/gradle/ is an equivalent Android-Studio skeleton. Staged .sos are llvm-stripped (--no-strip to keep symbols); optional engine cdylibs stage only when the bundle references their downdraft_<lib> token (--libs=/--exclude-libs= to override); --node-flavor=lite selects the lite libnode.
  • Lifecycle: on Android dd_window_create only records the request — the winit loop creates the Window on resumed() (or via EventLoopProxy wakeup). Wire events 15/16/17 = touch/suspended/resumed; NativeWindow blocks for the first RESUMED, drops+rebinds the wgpu surface across suspend/resume, and synthesizes pointer+mouse events from touch.
  • ABI note: engine cdylibs ship as separate lib/<abi>/libdowndraft_*.so and are resolved by bare soname (lib-paths.ts android branch). libdowndraft_platform.so is intentionally not shipped standalone — it would duplicate the event-queue statics.
  • Env: shell sets HOME, TMPDIR, DOWNDRAFT_DATA_DIR (= internalDataPath), DOWNDRAFT_BUNDLE_DIR (= extracted bundle root; packaged bundles resolve import.meta.dir/assets/workers under it).
  • API floor: minSdk 30 (Android 11, ~87% install base) — covers the bionic surface libuv wants (statx/faccessat2/memfd/pthread_cond_clockwait) and prunes the bad-Vulkan-driver era. Override: --min-sdk (packager), --android-api (build-native.mjs), --sdk (build-android.mjs), DD_MIN_SDK (Gradle). Target SDK is 36.