Repository navigation
Conversation
Map the Android ABI to its Rust target and give cargo the NDK's compiler, archiver and sysroot, as cargo-ndk does. When cross-compiling, use a host protoc, checked against the vendored Protobuf version, and build the UniFFI metadata library for the target. On Android, livekit-ffi trusts its bundled webpki roots, as LiveKit's own Android FFI builds do, since rustls-native-certs doesn't find Android's CA certificates. There's no system libcurl or OpenSSL, so HTTP token sources return an error there. Configuring with a static C++ runtime now warns, since apps then can't catch the SDK's exceptions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Android builds with different API levels or NDKs can overwrite shared Cargo artifacts and package the wrong library, while the protoc lookup can select a target binary that cannot run on the host.
2 open issues
What changed in this PR
Adds Android cross-compilation support to the C++ SDK and its Rust FFI build using the NDK toolchain, with documentation for application integration.
Changes:
- Configures Android Rust targets, NDK tools, bundled certificate roots, and target-built UniFFI metadata.
- Uses a version-checked host
protocfor cross-compilation and disables curl/OpenSSL dependencies on Android. - Documents Android prerequisites, packaging, JNI setup, and the HTTP token-source limitation.
| File | Description |
|---|---|
src/token_source_http.cpp |
Returns an explicit unsupported error for Android HTTP token requests. |
docs/building.md |
Documents Android builds and runtime integration requirements. |
CMakeLists.txt |
Adds Android target, toolchain, TLS, and dependency configuration. |
cmake/uniffi_cpp.cmake |
Builds UniFFI metadata for the selected target. |
cmake/run_cargo.cmake |
Passes Android toolchain settings and feature flags to Cargo. |
cmake/protobuf.cmake |
Selects and version-checks host protoc when cross-compiling. |
Review effort: Balanced
| set(LIVEKIT_ANDROID_CC | ||
| "${_lk_android_toolchain_bin}/${_lk_android_clang_triple}${_lk_android_api}-clang") |
| if(CMAKE_CROSSCOMPILING) | ||
| # A protoc built for the target can't run during the build, so use one for the build machine. Its version must | ||
| # match the vendored runtime, which only accepts code generated by the same release. | ||
| find_program(Protobuf_PROTOC_EXECUTABLE NAMES protoc REQUIRED) |
Builds for the same ABI with a different NDK or API level shared a Cargo directory, so one could package the other's livekit_ffi. Also look up the host protoc outside the cross-compiling sysroot, and list the host protoc and the Android exceptions in the Dependencies table. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@mdepinet Thanks for the contribution. For our existing C++ customers and applications, Android is not critical path for us currently. While your changes aren't that impactful as-written, a couple things come to mind:
We also don't internally build against Android with this C++ SDK, and would likely want to test on actual platforms. This becomes additional overhead each release. Also within LiveKit, we have: https://github.com/livekit/client-sdk-android Given our team's resources and priorities, adding another supported platform is a big consideration. Our team discussed this internally, are we're not going to accept this PR at this time. Being open source - I encourage you to maintain a fork of this SDK and keep the head commit on top of ours with any Android-related changes you need. If such a fork gains traction/adoption, we can certainly reconsider official support. Thanks :)
|
|
Thanks for the thoughtful response, Alan. |


This lets the SDK cross-compile for Android with the NDK's CMake toolchain file. We use client-sdk-cpp in a Godot plugin (godot-livekit) that ships on Android, which has meant depending on a fork until now. We didn't find an issue, PR or roadmap item about Android, so this PR is partly a question: if Android isn't something you want to take on, feel free to close it.
Changes
ANDROID_ABIto the Rust target (arm64-v8a,armeabi-v7a,x86_64). Give cargo, the cc crate and bindgen the NDK's compiler, archiver and sysroot for the build's ABI and API level, as cargo-ndk does.rustls-tls-webpki-rootsinstead of the default native roots, as LiveKit's own Android FFI builds do. rustls-native-certs doesn't find Android's CA certificates.protoc, checked against the vendored Protobuf version. The vendored build can't produce a protoc that runs on the host.tokenSourceHttpRequest()returns an error there.std::runtime_erroraborting the app.docs/building.mdgets a "Cross-compiling for Android" section. It covers prerequisites (NDK r27+, since webrtc-sys doesn't compile with r26) and what apps need:libc++_shared.so,libwebrtc.jar, and loadinglivekit_ffiwithSystem.loadLibrary.Non-Android builds are unaffected, except that any cross-compiling build now uses a host protoc.
Testing
arm64-v8a,armeabi-v7aandx86_64with NDK r27d, and natively for Linux x86_64.livekit-server --dev. These cover connecting, audio and video, data, RPC, E2EE and disconnecting. All passed, except tests that fail for reasons unrelated to this change (a timing-sensitive warning in the plugin, and screen capture, which the plugin doesn't build on Android).arm64-v8abuild loads and passes the tests that don't need WebRTC under the emulator's ARM translation. The rest need a JavaVM lookup that the translation layer doesn't provide. We haven't tried a physical device yet.Not included
builds.ymlif you'd like one.build.shsupport. The docs use CMake directly, sincebuild.shdoesn't take a toolchain file.Questions
Written with Claude Opus 5.5 (an AI model by Anthropic), working with @mdepinet.
🤖 Generated with Claude Code