Android

Run BUI on a phone from C, Lua or Rust with the same code as on a desktop. One NativeActivity, no Java and no Gradle, damage-driven software rendering, touch that scrolls, the soft keyboard, and an APK of about 1 to 2 MB.

On Android the kit’s window is the activity’s surface (kit/intern/kit_window_android.c, which implements BK_window_* like the Windows and Linux hosts do). An app opens a window and runs it exactly as on a desktop, so Rust, Lua and C apps are the code they would be anywhere else. Nothing changes for other platforms: the Android code is in platform/android, the kit’s Android-only branches and if(ANDROID) blocks.

python platform/android/build.py # the C demo: arm64-v8a + x86_64
python platform/android/build.py --lua examples/android # a Lua app
python platform/android/build.py --rust platform/android/rust # a Rust app
python platform/android/build.py --js app.jsx # JavaScript: React, Vue, Svelte
python platform/android/build.py --imgui # Dear ImGui (C++)
python platform/android/build.py --install # install and start it

You need the Android SDK (ANDROID_HOME), an NDK, CMake and a JDK for keytool; Rust also needs the Android targets (rustup target add aarch64-linux-android x86_64-linux-android).

Your app

src/lib.rs
use blenderui::prelude::*;
struct MyApp;
impl Render for MyApp {
fn render(&mut self, _: &mut Window, _: &mut Context<Self>) -> impl IntoElement {
app().child(h1().child("Hello, Android")).child(button().child("Go"))
}
}
#[unsafe(no_mangle)]
pub extern "C" fn bui_app_main() {
Application::new().run(|cx: &mut App| {
cx.open_window(WindowOptions::default(), |_, cx| cx.new(|_| MyApp)).unwrap();
});
}

A staticlib crate (see platform/android/rust). Give the root a definite height (.css("height", "100vh")) with overflow_y_scroll() to scroll.

Python, Qt, tkinter and D need their runtime on the device and are not available on Android.

How it behaves

  • Damage driven. The thread sleeps until a touch, key, timer or frame request, and only the damaged rectangles are converted and locked. An idle app uses no CPU.
  • Scale. A CSS pixel is a dp, as in Chrome on Android.
  • Touch. One finger is the pointer and a tap is a click. A drag that starts on a widget that drags (sliders, text, scrollbars) drags it; anywhere else it scrolls, following the finger exactly and carrying on after it lifts with the deceleration of iOS’s scroll views. A touch at the right edge of a custom node drags the app’s scrollbar, so a list of millions of rows can be dragged to any place. Two fingers always scroll.
  • Keyboard. It opens while a text field is edited (through the input method manager, since the activity’s view is not a text editor); keys arrive as key events. Predictive keyboards and IME composition are not wired up yet.
  • Lifecycle. One activity: launching the app while it runs brings it back, and after Back finishes it the next launch runs bui_app_main again from a fresh start, even in the same process. A Lua script that fails shows its error on screen, also after it opened its window.
  • Big lists. The Rust demo scrolls a list of 10 million rows and a chat of 100 000 messages (blenderui::vlist): only the rows in view exist, so a frame costs the visible rows, not the list.
  • Fonts. The system’s Roboto is used (Inter is left out, 0.8 MB). Register your own with BUI_text_add_font and select it with BK_set_font.
  • Size. About 1.1 MB per ABI for the C demo, 1.4 MB with Lua and 2.0 MB with Rust (arm64-v8a).
Edit this page on GitHub

Last updated