fix Android PlatformAudio#1104
Open
xianshijing-lk wants to merge 1 commit into
Open
Conversation
Contributor
ChangesetThe following package versions will be affected by this PR:
|
cloudwebrtc
approved these changes
May 20, 2026
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.
Before you submit your PR
Make sure the following is true before submitting your PR:
PR description
⏺ Android PlatformAudio: Problems & Solutions
Problem 1: ADM Creation Failed
Symptom:
CreateAudioDeviceModule returned nullptr
Failed to initialize PlatformAudio
Root Cause:
WebRTC's CreateAndroidAudioDeviceModule internally calls GetAppContext() to get the Android application context. But GetAppContext() returns null unless ContextUtils.initialize(context) was called first.
CreateAndroidAudioDeviceModule()
└── GetAppContext()
└── Returns null ❌ (ContextUtils not initialized)
Solution:
Pass the Android Context from Unity to Rust, then call ContextUtils.initialize(context) before any WebRTC audio initialization.
Unity Rust/C++
───── ────────
GetApplicationContext() ──────► livekit_ffi_initialize_android_context()
│
├── do_android_init(vm) // JVM init
└── ContextUtils.initialize(context) // Now GetAppContext() works!
Files changed:
Problem 2: Wrong ADM Factory Function
Symptom:
AdmProxy: All Android audio layers failed!
Root Cause:
The code was using the generic CreateAudioDeviceModule() which doesn't work properly on Android. Android requires CreateAndroidAudioDeviceModule() from the Android-specific header.
Solution:
Changed adm_proxy.cpp to use the correct function:
// Before (wrong):
#include "modules/audio_device/include/audio_device.h"
platform_adm_ = webrtc::AudioDeviceModule::Create(...);
// After (correct):
#include "sdk/android/native_api/audio_device_module/audio_device_android.h"
platform_adm_ = webrtc::CreateAndroidAudioDeviceModule(...);
File changed:
Problem 3: Empty GUID Validation Failed
Symptom:
Recording device at index 0 has no GUID
Root Cause:
Unity SDK threw an exception when device GUID was empty. But on Android, devices don't have GUIDs - WebRTC returns empty strings.
Solution:
Allow empty GUIDs and pass them to native code, which falls back to index 0:
// Before:
if (string.IsNullOrEmpty(deviceId))
throw new InvalidOperationException("has no GUID");
// After:
SetRecordingDevice(deviceId ?? ""); // Empty string triggers fallback
File changed:
Problem 4: Device Not Found with Empty GUID
Symptom:
Failed to set recording device: Device not found
Root Cause:
Native code searched for a device matching the empty GUID string, found nothing.
Solution:
Added fallback in C++ - if GUID is empty and devices exist, use index 0:
bool AudioDeviceController::set_recording_device_by_guid(rust::String guid) const {
int16_t count = adm_proxy_->RecordingDevices();
}
File changed:
Breaking changes
N/A
MSRV
N/A
Testing
Tested with Unity
Async
N/A