lingxia
lingxia is the public Rust entry crate for LingXia native host apps.
It has two intentionally different API surfaces:
- Platform bootstrap / FFI APIs used by generated Android, Apple, and Harmony host projects to start the LingXia runtime.
- Business APIs used by app-owned Rust code to implement native features such as downloads, file dialogs, media, logging, and updates.
Most application crates should depend on lingxia only. Lower-level crates such as lingxia-lxapp, lingxia-service, lingxia-transfer, and platform crates are implementation layers unless you are working on the framework itself.
1. Platform Bootstrap / FFI
The platform modules are target-gated and are consumed by host app templates, SDK glue code, and generated platform projects.
| Module | Target | Purpose |
|---|---|---|
lingxia::android |
Android | JNI entry points and Android runtime bridge |
lingxia::apple |
iOS / macOS | Swift bridge entry points and Apple runtime bridge |
lingxia::harmony |
HarmonyOS | NAPI entry points and Harmony runtime bridge |
App developers usually do not call these modules directly. The generated platform project wires them into the target app bootstrap.
Native libraries can register app-owned startup behavior through HostAddon:
;
Generated host templates call this registration function from the platform entry point before runtime initialization.
2. Business APIs
Business APIs are the stable surface for app-owned Rust code. They are organized by developer task, not by internal crate layout.
| API | Use for |
|---|---|
#[lingxia::native] |
Expose Rust functions to lxapp pages |
lingxia::host |
Stream, channel, cancellation, and host route helpers |
lingxia::app |
App metadata and app-scoped state paths |
lingxia::file |
Download, upload, file picker, preview, reveal, and external open |
lingxia::media |
Camera, scanner, media picker, and media preview |
lingxia::log |
App logging stream and downstream logger registration |
lingxia::task |
Spawn async or blocking work on LingXia's runtime |
lingxia::update |
Host app update check/apply APIs for custom native UI |
lingxia::provider |
Provider traits for cloud, update, media, push, and other integrations |
lingxia::js |
Optional JS AppService extensions when standard is enabled |
Native Page APIs
Use #[lingxia::native] to expose app-owned Rust functions to pages:
use Arc;
async
File Download
lingxia::file::download downloads into the app-managed user cache. App code does not choose temp paths or internal cache directories.
let file = download
.await?;
println!;
File And Media UI
Use facade modules instead of platform-specific SDK calls:
let files = choose_file.await?;
let media = choose_media.await?;
review.await?;
Host App Update
By default, LingXia can run the built-in host app update UX. Apps that need a custom native UI can opt into custom mode and drive the checked update handle:
use_custom_host_app_update;
if let Some = check_host_app_update.await?
The update facade intentionally does not expose package paths, caller-supplied current versions, or separate download/install entry points.
API Boundary
lingxia should stay small and app-oriented.
Use lingxia for:
- platform bootstrap exports required by generated host apps
- app-owned native route authoring
- stable business facades such as
app,file,media,log,task, andupdate - provider traits that app integrations implement
Do not use lingxia as a shortcut to runtime internals:
- page lifecycle orchestration belongs below the facade
- shell products such as downloads/settings management stay behind shell or logic APIs
- whole internal crates should not be re-exported just because they exist
For more detail, see docs/native-development.md
and docs/internal/lingxia-facade-boundary.md.