-
Notifications
You must be signed in to change notification settings - Fork 140
Get Rust SDK Android Example working #859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
xianshijing-lk
merged 5 commits into
main
from
sxian/CLT-2516/fix_rust_sdk_android_example
Feb 6, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d965187
initial version that seems functional
xianshijing-lk bf54c9a
addressed the comments
xianshijing-lk 14e2c8b
removed the unneeded files
xianshijing-lk af6d0a3
Update examples/mobile/android/app/src/main/java/io/livekit/rustexamp…
xianshijing-lk 5e9e313
Merge branch 'main' into sxian/CLT-2516/fix_rust_sdk_android_example
xianshijing-lk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Binary file not shown.
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
88 changes: 85 additions & 3 deletions
88
examples/mobile/android/app/src/main/java/io/livekit/rustexample/App.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,91 @@ | ||
| package io.livekit.rustexample | ||
|
|
||
| import android.util.Log | ||
|
|
||
| class App { | ||
| private val nativeAvailable: Boolean | ||
|
|
||
| init { | ||
| System.loadLibrary("mobile") | ||
| nativeAvailable = try { | ||
| System.loadLibrary("mobile") | ||
| true | ||
| } catch (error: UnsatisfiedLinkError) { | ||
| Log.w(TAG, "Native library not found; skipping LiveKit init.", error) | ||
| false | ||
| } | ||
| } | ||
|
|
||
| // Connection methods | ||
| private external fun connectNative(url: String, token: String) | ||
| private external fun disconnectNative() | ||
| private external fun isConnectedNative(): Boolean | ||
|
|
||
| // Audio methods | ||
| private external fun pushAudioNative(samples: ShortArray): Int | ||
| private external fun pullAudioNative(buffer: ShortArray): Int | ||
| private external fun getPlaybackBufferSizeNative(): Int | ||
|
|
||
| fun connect(url: String, token: String) { | ||
| if (!nativeAvailable) { | ||
| Log.w(TAG, "LiveKit native library unavailable; connect() ignored.") | ||
| return | ||
| } | ||
| connectNative(url, token) | ||
| } | ||
|
|
||
| fun disconnect() { | ||
| if (!nativeAvailable) { | ||
| Log.w(TAG, "LiveKit native library unavailable; disconnect() ignored.") | ||
| return | ||
| } | ||
| disconnectNative() | ||
| } | ||
|
|
||
| fun isConnected(): Boolean { | ||
| if (!nativeAvailable) { | ||
| return false | ||
| } | ||
| return isConnectedNative() | ||
| } | ||
|
|
||
| /** | ||
| * Push captured microphone audio to LiveKit. | ||
| * @param samples 16-bit PCM samples (mono, 48kHz expected) | ||
| * @return Number of samples consumed | ||
| */ | ||
| fun pushAudio(samples: ShortArray): Int { | ||
| if (!nativeAvailable) { | ||
| return 0 | ||
| } | ||
| return pushAudioNative(samples) | ||
| } | ||
|
|
||
| /** | ||
| * Pull playback audio from LiveKit (remote participants). | ||
| * @param buffer Buffer to fill with 16-bit PCM samples | ||
| * @return Number of actual samples written (rest is silence) | ||
| */ | ||
| fun pullAudio(buffer: ShortArray): Int { | ||
| if (!nativeAvailable) { | ||
| return 0 | ||
| } | ||
| return pullAudioNative(buffer) | ||
| } | ||
|
|
||
| external fun connect(url: String, token: String) | ||
| } | ||
| /** | ||
| * Get the number of samples available in the playback buffer. | ||
| * Useful for monitoring buffer health. | ||
| */ | ||
| fun getPlaybackBufferSize(): Int { | ||
| if (!nativeAvailable) { | ||
| return 0 | ||
| } | ||
| return getPlaybackBufferSizeNative() | ||
| } | ||
|
|
||
| fun isNativeAvailable(): Boolean = nativeAvailable | ||
|
|
||
| private companion object { | ||
| private const val TAG = "LiveKitApp" | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.