Skip to content

Android

The native SDK on Android is libsona.so, one per ABI: arm64-v8a for phones and tablets, x86_64 for the emulator and the few x86 devices. Android 7.0 (API 24) and later. It draws with Vulkan 1.1 or OpenGL ES 3.0, on a device and context your app owns, exactly as on Linux. The device code below is C, as the NDK's Vulkan and EGL handles are; C++ uses it as it is, and the C#, Rust and Python bindings fill the same sona_device_desc in their raw layers (Native.sona_device_desc, sona_sys::sona_device_desc, sona._native).

Files lib/arm64-v8a/libsona.so, lib/x86_64/libsona.so, include/sona.h
Minimum API 24 (Vulkan needs it), NDK r23 or newer to build against it
Backends SONA_BACKEND_VULKAN, SONA_BACKEND_GLES
Pages Every LOAD segment aligned to a fixed 16 KB (Google Play requires it for apps targeting Android 15)
sona_platform() android-arm64 or android-x64; your sona-licence.json must list the one you ship
HTTP None built in. To read from the gate, pass your own sona_config.http (below)

Using it in an app

Package the library. With Gradle, copy each libsona.so to app/src/main/jniLibs/<abi>/. Your own native code links against it; in its CMakeLists.txt:

add_library(sona SHARED IMPORTED)
set_target_properties(sona PROPERTIES
  IMPORTED_LOCATION "${CMAKE_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}/libsona.so"
  INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/sona/include")
target_link_libraries(mygame PRIVATE sona vulkan android log)

Ship only the ABIs you list in abiFilters. Release builds of libsona.so are already stripped.

The licence. sona_config.licence takes the bytes of sona-licence.json. Keep the file in assets/ and read it with AAssetManager_open and AAsset_getBuffer; the core never opens it by path.

Folders. A SONA_SOURCE_DIR source is a real folder: use your app's files or cache directory (Context.getFilesDir(), passed down through JNI). Files inside the APK's assets/ are not a folder.

HTTP. Android has no HTTP layer in the core, so sona_http_platform() returns NULL. A gate source needs sona_config.http: a send that starts the request on your own stack (OkHttp or HttpURLConnection through JNI, or a libcurl you build) and calls sona_http_done from any thread when it finishes.

Vulkan. Hand over the device your renderer already made:

sona_device_desc dev = {0};
dev.backend = SONA_BACKEND_VULKAN;
dev.u.vk.instance = instance;
dev.u.vk.physical_device = physical_device;
dev.u.vk.device = device;
dev.u.vk.queue = queue;
dev.u.vk.queue_family = queue_family;
dev.u.vk.api_version = VK_API_VERSION_1_1;
/* wraps vkGetInstanceProcAddr */
dev.u.vk.get_instance_proc = my_get_instance_proc;
dev.frames_in_flight = 2;
sona_renderer_create(ctx, &dev, &renderer);

Then sona_draw records into your command buffer each frame, onto your swapchain image or an offscreen one (sona_target.u.vk, an RGBA8 or BGRA8 UNORM view), and sona_renderer_frame_done follows each fence. The offscreen_vk sample (samples/c/offscreen_vk.c) is the whole loop in one file and builds for Android as is.

OpenGL ES. With your EGL context current, dev.backend = SONA_BACKEND_GLES and dev.u.gl.get_proc set to a function that calls eglGetProcAddress.

Lifecycle. Losing the window takes only your swapchain: each sona_draw names its target, so the renderer carries on once you have a new one. If the GLES context goes with the surface (the default for GLSurfaceView on pause), call sona_renderer_lost, then sona_renderer_reset with the new context. The sona_ctx and its avatars survive either way.

This page as Markdown · All the docs as one file (llms-full.txt)