diff --git a/.changeset/webrtc-init-latch-after-success.md b/.changeset/webrtc-init-latch-after-success.md new file mode 100644 index 000000000..192bfe1c2 --- /dev/null +++ b/.changeset/webrtc-init-latch-after-success.md @@ -0,0 +1,5 @@ +--- +"client-sdk-android": patch +--- + +Fix: only latch WebRTC initialization after PeerConnectionFactory.initialize succeeds, so a failed native library load stays retryable and surfaces as a catchable exception instead of poisoning the process and crashing on the next LiveKit.create() call. diff --git a/livekit-android-sdk/src/main/java/io/livekit/android/dagger/RTCModule.kt b/livekit-android-sdk/src/main/java/io/livekit/android/dagger/RTCModule.kt index e8d78fa43..2a0591a96 100644 --- a/livekit-android-sdk/src/main/java/io/livekit/android/dagger/RTCModule.kt +++ b/livekit-android-sdk/src/main/java/io/livekit/android/dagger/RTCModule.kt @@ -103,7 +103,6 @@ internal object RTCModule { if (!hasInitializedWebrtc) { executeBlockingOnRTCThread(LibWebrtcInitializationThreadToken) { if (!hasInitializedWebrtc) { - hasInitializedWebrtc = true PeerConnectionFactory.initialize( PeerConnectionFactory.InitializationOptions .builder(appContext) @@ -128,6 +127,12 @@ internal object RTCModule { ) .createInitializationOptions(), ) + // Only latch after initialize succeeds. If it throws (e.g. the native + // library fails to load), latching beforehand would permanently skip + // initialization for the process, and the next native call would crash + // with an uncatchable-by-catch(Exception) UnsatisfiedLinkError instead + // of a catchable failure at the call site. + hasInitializedWebrtc = true } } }