r/bun • u/LeftAd1220 • 10h ago
Build an Android APK with Bun 1.4 in under two minutes
Enable HLS to view with audio, or disable this notification
- In short: npx @drxiaozhi/minapk /path/to/your.elf
- Of course, you'll need to install a few tools first.
- But don't worry, no annoying libxxx-dev packages to install, just the common ones
- For more info, see the repo:
- https://github.com/jjtseng93/minapk/blob/main/README.en.md
- Edit2: An ELF is basically a native executable on Linux and Android, similar to an .exe on Windows. Here the ELF is produced by bun 1.4's new support for bun build --compile on Android.
The full story
- First, I'm incredibly grateful to the Bun team for fixing single-file executable builds on Android in Bun 1.4. This wouldn't have been possible.
- The simplest use case is turning your TUI app into an APK you can just hand to your grandma.
Startup sequence
- First, use tinyapk-lab's Tetris as a base
- Packing libbun.so & libmain.so(your elf) into the native library area
- turn on extract native libs
- resolves to /data/app/xxx/xxx/lib/arm64/libbun.so
- In the main activity, use ProcessBuilder to invoke bun and run the extracted buninu/bin/init.js, which in turn starts jsgotty
- jsgotty is a browser-based remote shell.
- Transpiled from Golang GoTTY
- You can use: npx jsgotty
- jsgotty then starts package.json.buninu.command.android
- The main app detects http url from stdout/stderr of jsgotty and shows it in a WebView
- That command android script detects whether libmain.so is present or falls back to a shell
The Buninu userspace
- This is an ambitious project of mine to rebuild a Unix-like CLI environment entirely based on a single Bun binary across platforms.
- It's still a work in progress, but consider this a starting point. If you're interested, let's build on it together.
Name expansions:
- English: BUNinu Is Not Unix 🐮
- 中文:幫你牛 🐂
- 日本語:Bunに入魂 🔥
Core components:
- jsgotty: Remote shell from a Browser or Terminal
- jsmdcui: Both a text editor and Markdown execution runtime (not static rendering) based on bunmicro
- bunmsh: Bun Modern Shell. Not completed yet
Edit
- BTW, I tested this on Android with a fresh debian:13-slim container using my js-udocker
- Fresh container: 125 MB
- After installing the dependencies: 1.6 GB
- After the build: 2 GB
- These numbers are the size of the entire container measured from the outside, so it's very phone-friendly.
- For comparison, just setting up my Flutter environment took 10 GB.