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 <noreply@anthropic.com>
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
Comment on lines
+306
to
+307
| set(LIVEKIT_ANDROID_CC | ||
| "${_lk_android_toolchain_bin}/${_lk_android_clang_triple}${_lk_android_api}-clang") |
Contributor
Author
| 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) |
Contributor
Author
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 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


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