Android Example
A minimal Android mobile shell that embeds a Native SDK static library through JNI. The example keeps a native Android header above a WebView workspace and routes native navigation/header actions through the Native SDK command path.
Android views own the mobile shell layout: native header sizing, density-aware resize events, touch forwarding, and the WebView workspace. The Native SDK runtime is driven through JNI calls into the C ABI.
Build the native library
Build or package an Android static library from the repository root, then copy it into this example:
zig build lib -Dtarget=aarch64-linux-android
mkdir -p examples/android/app/src/main/cpp/lib
cp zig-out/lib/libnative-sdk.a examples/android/app/src/main/cpp/lib/libnative-sdk.a
The CMake project expects the library at app/src/main/cpp/lib/libnative-sdk.a and the C header at app/src/main/cpp/native_sdk.h.
Run
Open examples/android in Android Studio, or build from the command line with a configured Android SDK:
./gradlew :app:assembleDebug
Install on an emulator or device:
./gradlew :app:installDebug
Files
app/src/main/java/dev/native_sdk/examples/android/MainActivity.kthosts native Android chrome, a WebView workspace, aSurfaceView, and the JNI bridge.app/src/main/cpp/native_sdk_jni.cforwards JNI calls to the Native SDK C ABI.app/src/main/cpp/CMakeLists.txtimportslibnative-sdk.aand builds the JNI shared library.app.zonrecords the mobile example metadata for Native SDK tooling.
Host lifecycle
onCreateloads the JNI library, creates the native shell, then starts the Native SDK app.onResumeandonPauseforward activation lifecycle withnative_sdk_app_activateandnative_sdk_app_deactivate.surfaceChangedforwards size, display density, safe-area insets, keyboard inset, and the AndroidSurface, then requests a frame.- Orientation and screen-size changes stay in the same activity so the embedded runtime is not recreated during rotation.
- The activity uses
windowSoftInputMode="adjustResize"so Android owns keyboard avoidance and relayouts the content area. - The native Back and Refresh buttons call
nativeCommandwith stable mobile command IDs, update status fromnative_sdk_app_last_command_count, and request a frame. - The Android system Back action dispatches
mobile.backthrough the same command path. onTouchEventforwards pointer id, phase, position, and pressure.- The JNI bridge exposes hardware key, committed text, and IME composition entry points for GPU/widget text fields.
- The embedded C ABI can expose retained GPU/widget accessibility semantics by indexed snapshot and dispatch widget accessibility actions for Android accessibility providers.
surfaceDestroyedandonDestroystop and destroy the app.
The app.zon shell view tree describes this header and WebView workspace. Native mobile layout is still implemented in Kotlin so Android owns soft-keyboard relayout, Back handling, orientation changes, and activity lifecycle while the Native SDK receives the viewport metrics needed for GPU/widget layout.