Error Unity DllNotFoundException: Unable to load DLL 'webrtc'

Unity Editor version: 2022.3.1f1
Unity package version: 1.8.0
ML2 OS version: 1.3.0-dev2
MLSDK version: 1.3.0-dev2

We are currently blocked on com.unity.webrtc not working at this MLSDK version, so I decided to try the MLWebRTC API. The C# bindings are all still available, but it seems the native code DLL could not be found.

I have been experimenting with the MLWebRTC.PeerConnection.CreateRemote() call because it is the first call into the WebRTC library in our scenario. The sample code in, when run on the headset, produces a non-null connection and result.IsOk. The same call run in the simulator produces a NotImplementedException, which I presume is expected behaviour.

When I attempt the same CreateRemote() call in our app, there is a managed code NullReferenceException that is proceeded by this message:

webrtc DLL not found

2023-07-28 14:58:24.397 28752 28774 Error Unity DllNotFoundException:
Unable to load DLL 'webrtc'. Tried the load the following dynamic libraries:
Unable to load dynamic library 'webrtc' because of 'Failed to open the
requested dynamic library (0x06000000) dlerror() = dlopen failed: library "webrtc" not found

Then the NullReferenceException

System.NullReferenceException: Object reference not set to an instance of an object.
at UnityEngine._AndroidJNIHelper.GetSignature (System.Object obj) [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine._AndroidJNIHelper.GetSignature[ReturnType] (System.Object args) [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine._AndroidJNIHelper.GetMethodID[ReturnType] (System.IntPtr jclass, System.String methodName, System.Object args, System.Boolean isStatic) [0x00000] in <0000000000000000000000000
at UnityEngine.AndroidJavaObject._CallStatic[ReturnType] (System.String methodName, System.Object args) [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.XR.MagicLeap.MLPermissions.CheckPermissionInternal (System.String permission) [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.XR.MagicLeap.MLPermissions.CheckPermission (System.String permission) [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.XR.MagicLeap.MLWebRTC+PeerConnection.CreateRemote (UnityEngine.XR.MagicLeap.MLWebRTC+IceServer iceServers, UnityEngine.XR.MagicLeap.MLResult& result) [0x00000] in <00000000000
at Assets.RemoteSpark.Scripts.WebRTC.ML.MLPeerConnection..ctor (KSpark.Telemetry.KSparkLogger logger) [0x00000] in <00000000000000000000000000000000>:0
at Assets.RemoteSpark.Scripts.WebRTC.ML.MLWebRTCProvider.CreatePeerConnection () [0x00000] in <00000000000000000000000000000000>:0
[... snip ...]

We have been comparing the failing code in our app to the successful sample code, but cannot find the cause. It seems like it must be a project setup detail, but I'm just guessing. Do you have any advice for what might cause this, or how to investigate further?

Hi @ks-scott,

Welcome to the Magic Leap 2 Developer forums. We are grateful to have you here engaging with us.

I found a tool that may be able to help find the missing dependencies. Let me know if this is helpful for you.



Thanks @etucker for the quick reply. Full disclosure: I am a newcomer to both Unity development and the Magic Leap platform, so I could easily be missing something that you would expect to be obvious.

I have used that Dependencies tool many times -- it can indeed be a life saver. But it's Windows only, no? I see in my post that I neglected to emphasize an important detail: the issue I'm having is specific to the Magic Leap headset, so an Android .so dependency I presume. I assume the reference to DLL is just because DllNotFoundException is a standard dotnet exception class that is used uniformly on all platforms.

I think the call to PeerConnection.CreateRemote() is the first call into the MLWebRTC API, which -- I'm guessing -- triggers an attempt to load the native code which for some reason is not on the library path. As I am an Android/ML2/Unity newbie, I wonder if I have just missed a project or player setting that would include in the build. Or something. I don't know where it is meant to be sourced from or where in the build process I would look to see what is going on.

Hi @ks-scott the com.unity.webrtc package is not fully supported by Magic Leap at this time. We are investigating an issue with the Plugin that prevents Magic Leap applications from initializing correctly.

That said, the reason why you are running into a Unable to load DLL issue is because Unity has not released the x86_64 compatible version yet. The build script has been updated 2 weeks ago in the project repository. If you want to try to use it in your Magic Leap 2 project you will need to manually build the plugin from the main branch.