client-sdk-unity icon indicating copy to clipboard operation
client-sdk-unity copied to clipboard

Unable to load liblivekit_ffi.so on android arm 64

Open holofermes opened this issue 9 months ago • 5 comments

The new liblivekit_ffi.so is not loading on an android phone with arm 64 architecture - I tried on a Samsung S22, and an S24.

This is the error reported by Unity:

Unity LiveKit: System.DllNotFoundException: Unable to load DLL 'livekit_ffi'. Tried the load the following dynamic libraries: Unable to load dynamic library 'livekit_ffi' because of 'Failed to open the requested dynamic library (0x06000000) dlerror() = dlopen failed: library "livekit_ffi" not found
Unity   at LiveKit.Internal.NativeMethods.FfiNewRequest (System.Byte* data, System.Int32 len, System.Byte*& dataPtr, System.UIntPtr& dataLen) [0x00000] in <00000000000000000000000000000000>:0 
Unity   at LiveKit.Internal.FfiClient.SendRequest (LiveKit.Proto.FfiRequest request) [0x00000] in <00000000000000000000000000000000>:0 
Unity   at LiveKit.Internal.FFIClients.Requests.FfiRequestWrap`1[T].Send () [0x00000] in <00000000000000000000000000000000>:0 
Unity   at LiveKit.Internal.FFIClients.Requests.FFIBridgeExtensions.SendConnectRequest (LiveKit.Internal.FFIClients.Requests.IFFIBridge ffiBridge, System.String url, System.String authToken, LiveKit.RoomOptions roomOptions) [0x00000] in <00000000000000000000000000000000>:0 

Kind of stabbing in the dark here, but this is what ldd returns on the .so file:

        linux-vdso.so.1 => [vdso] (0x7020c80000)
CANNOT LINK EXECUTABLE "linker64": cannot locate symbol "__assert_fail" referenced by "/data/app/my-apk/lib/arm64/liblivekit_ffi.so"...

And this is what readelf -d returns:

 0x0000000000000001 (NEEDED)             Shared library: [libm.so]
 0x0000000000000001 (NEEDED)             Shared library: [libEGL.so]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so]
 0x0000000000000001 (NEEDED)             Shared library: [liblog.so]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so]

The previous .so works fine, ldd resolves all the dependencies, and readelf -d shows:

 0x0000000000000001 (NEEDED)             Shared library: [libm.so]
 0x0000000000000001 (NEEDED)             Shared library: [libEGL.so]
 0x0000000000000001 (NEEDED)             Shared library: [libOpenSLES.so]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so]
 0x0000000000000001 (NEEDED)             Shared library: [liblog.so]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so]

It looks like the libOpenSLES.so dependency is missing from the new .so file.

holofermes avatar Apr 29 '25 06:04 holofermes

Just updated from Livekit 1.0.1 to the latest 1.2.0. Having the same issue running on the Magic Leap 2 (Android).

This did not occur in 1.0.1

KarlSupertramp avatar May 15 '25 06:05 KarlSupertramp

Thank you both for reporting, I will take a look to see what's going on.

ladvoc avatar May 15 '25 06:05 ladvoc

Two follow-up questions:

  1. What version of Android are you deploying to?
  2. What version of Unity are you building with?

ladvoc avatar May 15 '25 09:05 ladvoc

@ladvoc

I'm deploying for Android API level 29 with Unity version 6000.0.44f1

KarlSupertramp avatar May 16 '25 08:05 KarlSupertramp

I just encountered this problem when I upgraded from version 1.1.0 to version 1.2.0. The Unity version is 2021.3.48f1

WaN9Bro avatar May 17 '25 07:05 WaN9Bro

@ladvoc

Just tried it with the latest 1.2.1, the same issue still occurs:

Image

Android API level 29 (x86_64) / Unity version 6000.0.44f1 / Device: Magic Leap 2

KarlSupertramp avatar May 21 '25 06:05 KarlSupertramp

I am developing on Meta Quest3 and have the same issue on v1.2.1.

This problem appear when I update from v1.1.0 to v1.1.1.

Android API level 32/ Unity version 2022.3.47f1 (same issue on 6000.0.37f1) / Device, Meta Quest3

yu-jinh avatar May 22 '25 21:05 yu-jinh

I have determined the automated build process which generates liblivekit_ffi.so for Android is broken, resulting in a library that cannot be loaded in Unity. This issue will be resolved in an upcoming patch release. Thank you for reporting.

ladvoc avatar May 24 '25 00:05 ladvoc

There are any update about this problem? I'm trying to build my solution on Android and when try to connect the Room, it give me the same output error.

CosmopolitiWideverse avatar May 30 '25 14:05 CosmopolitiWideverse

The problem still persists when building on MacBook Pro Apple M4 Pro directly to android phone: DllNotFoundException: Unable to load DLL 'livekit_ffi'. Tried the load the following dynamic libraries: Unable to load dynamic library 'livekit_ffi' because of 'Failed to open the requested dynamic library (0x06000000) dlerror() = dlopen failed: library "livekit_ffi" not found at LiveKit.Internal.NativeMethods.LiveKitInitialize (LiveKit.Internal.FFICallbackDelegate cb, System.Boolean captureLogs, System.String sdk, System.String sdkVersion) [0x00000] in <00000000000000000000000000000000>:0 at LiveKit.Internal.FfiClient.InitializeSdk () [0x00000] in <00000000000000000000000000000000>:0. See screenshots to see current Plugins folder and the inspector of Liblivekit_ffi and livekit_ffi:

Image Image Image

Is something done wrong?

thedrhax14 avatar Jun 03 '25 14:06 thedrhax14

I tried on windows and it worked but at first it didn't and it was the same error. With the same setup I just completely deleted the app from my phone and did clean installation and Dll exception doesn't occur. There is a different problem now but it is related to livekit server config.

I am still not sure what exactly fixed the issue.

thedrhax14 avatar Jun 03 '25 15:06 thedrhax14

having this same issue right now with 1.2.2 and unity 6000.1.4f1 building for my meta quest 3. are there any updates on this? i've tried uninstalling and rebuilding already to no avail

restics avatar Jun 03 '25 19:06 restics

Working with ChatGTP, I tried to build the application via Android Studio, importing the file .so directly in the assets project.

The application manages to load the file but crashes, according to Android Logcat this is due to an incorrect generation of the liblivekit_ffi.so file which lacks the x64 architecture.

ChatGTP suggested me to directly generate a .so file with the correct architecture using the LIveKit rust project: https://github.com/livekit/rust-sdks/tree/main

Unfortunately despite my countless attempts I can't generate the file due to an error during generation. I honestly don't know how to solve it

CosmopolitiWideverse avatar Jun 09 '25 07:06 CosmopolitiWideverse

Tried same here @CosmopolitiWideverse . Also I see some PR but seems only macos libs are updated (https://github.com/livekit/client-sdk-unity/pull/121). Btw I played also with meta of android plugins and still nothing unfortunetly.

24THEGuNNeR07 avatar Jun 09 '25 13:06 24THEGuNNeR07

Hi guys, I'm trying to build the module in Android. I can't understand why I'm getting this error.

2025/06/09 17:00:55.771 21919 21952 Error Unity DllNotFoundException: Unable to load DLL 'livekit_ffi'. Tried the load the following dynamic libraries: Unable to load dynamic library 'livekit_ffi' because of 'Failed to open the requested dynamic library (0x06000000) dlerror() = dlopen failed: library "livekit_ffi" not found 2025/06/09 17:00:55.771 21919 21952 Error Unity at LiveKit.Internal.NativeMethods.LiveKitInitialize (LiveKit.Internal.FFICallbackDelegate cb, System.Boolean captureLogs, System.String sdk, System.String sdkVersion) [0x00000] in <00000000000000000000000000000000>:0 2025/06/09 17:00:55.771 21919 21952 Error Unity at LiveKit.Internal.FfiClient.InitializeSdk () [0x00000] in <00000000000000000000000000000000>:0

I see liblivekit_ffi.so and libwebrtc.jar but i don't understand why and how is possibile this --> Unable to load DLL 'livekit_ffi'.

I'm using unity 2022 and client-sdk-unity 1.2.3, but i don't think that the problem is unity.

Furthermore, I noticed something strange:

dlopen failed: cannot locate symbol "__assert_fail" referenced by "liblivekit_ffi.so"

Exploring the liblivekit_ffi.so library, I noticed that this is present, and perhaps it is not being resolved correctly.

I think the problem is the presence of "__assert_fail".

SabeeenoGH avatar Jun 09 '25 16:06 SabeeenoGH

Together with @potitoaghilar and @CosmopolitiWideverse we managed to solve the issue by manually compiling the rust-sdks at this specific revision da5c713107d573f28e82d69d91f509dbf6df79e7 with the following build command:

cargo build -p livekit-ffi --target aarch64-linux-android --release --no-default-features --features "rustls-tls-webpki-roots" -j 1

The version of sdk that we have built is compatibile with the livekit v1.2.3.

Upon analyzing symbols in the original liblivekit-ffi.so file, we identified an incompatible Android architecture symbol: __assert_fail. This symbol was absent in both our newly compiled library and previous versions of the same library, confirming its incorrect inclusion in the original build.

SabeeenoGH avatar Jun 10 '25 20:06 SabeeenoGH

@ladvoc @SabeeenoGH I just tested it using the latest commit (main). The issue "Unable to load DLL 'livekit_ffi'" still occurs

(Android API 29, Unity 6000.0.44f1, x86_64)

KarlSupertramp avatar Jun 11 '25 06:06 KarlSupertramp

We will be trying to build on Mac using latest update and see if this worked this week.

thedrhax14 avatar Jun 11 '25 06:06 thedrhax14

can anyone try this branch? https://github.com/livekit/client-sdk-unity/pull/130 preliminary analysis may be that cargo-ndk and r25 and above compile so the .so is broken, but the reason is unknown

cloudwebrtc avatar Jun 12 '25 05:06 cloudwebrtc

Hi @cloudwebrtc, we have tried this branch #130 and the issue of Error Unity DllNotFoundException: Unable to load DLL 'livekit_ffi' and seems to be fixed confirming our assumption of the __assert_fail symbol. But, since yesterday we start noticing some weird behaviour on the mobile microphone input: the remote peer is not receiving any audio data/signal (the sound is empty) and nothing can be heard on the other side. We are not able to identify the root of the problem. We don't know if it is related to the microphone acquisition or to the data transmission. This effect is persistent both on our compiled version and yours. You can replicate this audio problem both on Android physical device and on the emulator too. We have tested also on iOS simulator and the audio is not affected by this audio issue. We have not tested on iOS physical device yet.

We are assuming that the problem is related to the rust-sdks. Someone with the proper expertise is able to identify the problem?

SabeeenoGH avatar Jun 12 '25 15:06 SabeeenoGH

@SabeeenoGH in RtcAudioSource.cs try to add macro for UNITY_ANDROID and set DefaultMicrophoneSampleRate to 24k (like for iOS currently). It fixed issue on Meta Quest 3S on my side.

24THEGuNNeR07 avatar Jun 13 '25 11:06 24THEGuNNeR07

Hmm, that's weird, I remember Unity on Android supported 48000 sample rate before this. maybe Unity updated something

cloudwebrtc avatar Jun 15 '25 12:06 cloudwebrtc

This has been addressed in the latest release, v1.2.4.

ladvoc avatar Jun 17 '25 07:06 ladvoc

@cloudwebrtc I tried different solutions about it. Looks like when the track is sent, it is set with 2 channels and in the AudioStream looks like there is a check about the channels. Since android microphones have only one channel, could it be that the channel check fails and the audio is not sent to the other client? @ladvoc Has this issue with audio from Android mobile also been fixed in this version?

CosmopolitiWideverse avatar Jun 17 '25 07:06 CosmopolitiWideverse

Hi guys, we tried the new release v1.2.4 and it seems that the library works on Android mobile devices. At the moment, the .so files related to the arm64 architecture seem to work, so good job.

However, I wanted to understand if an AEC has been implemented on the Android mobile side, because it seems that the incoming audio mixes with the device's microphone audio.

SabeeenoGH avatar Jun 17 '25 11:06 SabeeenoGH

We will be trying to build on Mac using latest update and see if this worked this week.

v1.2.5 works as expected on Android and builds on Mac Book Pro with no issues. We had to remove the package fro the unity project, then delete the repo completely, clone it again and add it again. Also, as a precaution we double checked the settings in the inspector of each dll to confirm that it is set correctly. We didn't have to run install.py from terminal

thedrhax14 avatar Sep 01 '25 12:09 thedrhax14