Unable to load DLL in Unity

Hello guys,

in order to make use of third party libraries in Unity I am currently trying to load a simple C++ library to my Unity project.
The C++ library consists of a single function that returns a random number.

I've built the DLL file via Visual Studio 2022 (new Dynamic-Link Library Project) and drag and dropped the resulting DLL file into Assets/Plugins (I also tried Assets/Plugins/Android and Assets/Plugins/Android/x86_64).

My Plugin-Inspector looks like this:
image

In my simple project I'm calling the function upon pressing a button to change the text of a text-field. However when I press the button I receive the following error:

Error messages from Android Logcat

2023/12/08 13:57:53.500 32535 32559 Error Unity DllNotFoundException: Unable to load DLL 'SampleNativeProject.dll'. Tried the load the following dynamic libraries: Unable to load dynamic library 'SampleNativeProject.dll' because of 'Failed to open the requested dynamic library (0x06000000) dlerror() = dlopen failed: library "SampleNativeProject.dll" not found
2023/12/08 13:57:53.500 32535 32559 Error Unity   at NativeSampleScript.getRandomNumber () [0x00000] in <00000000000000000000000000000000>:0 
2023/12/08 13:57:53.500 32535 32559 Error Unity   at NativeSampleScript.GetRandomNumberFromNative () [0x00000] in <00000000000000000000000000000000>:0 
2023/12/08 13:57:53.500 32535 32559 Error Unity   at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in <00000000000000000000000000000000>:0 
2023/12/08 13:57:53.500 32535 32559 Error Unity   at MixedReality.Toolkit.StatefulInteractable.OnLastSelectExited (UnityEngine.XR.Interaction.Toolkit.SelectExitEventArgs args) [0x00000] in <00000000000000000000000000000000>:0 
2023/12/08 13:57:53.500 32535 32559 Error Unity   at UnityEngine.Events.UnityEvent`1[T0].Invoke (T0 arg0) [0x00000] in <00000000000000000000000000000000>:0 
2023/12/08 13:57:53.500 32535 32559 Error Unity   at UnityEngine.XR.Interaction.Toolkit.XRBaseInteractable.OnSelectExited (UnityEngine.XR.Interaction.Toolkit.SelectExitEventAr

I'm using the following versions:
Unity Editor version: 2022.3.2f1
ML2 OS version: 1.4.1
MLSDK version: 1.4
Host OS: Windows 10

Edit v1: I have a feeling I should build my library with Android Studio instead of Visual Studio, does it matter?

Thanks in advance for any help, let me know if more information is needed.
Batu

What plugin are you creating? Does it support the Android x86_64 platform? Plugins for Android usually have a specific library for that (typically .a or .so extension) . If the plugin is a C# / .NET project it could still be incompatible due to an incorrect configuration in the plugin project such as the .NET version or using features that are not supported by Unity.

Right now I'm just testing to get a minimalistic plugin working. Essentiality its just a .h and a .cpp file with one function in it. I built it for x64 as can be seen here ..

After the build I receive lots of file.
image

And I used the .dll file and copy/pasted that into my Plugins folder in my Unity project.

Thank you for that information. It looks like you are targeting the x64 platform on windows instead of Android. Here is some basic documentation referring to Android app development inside Visual Studio : Cross-Platform Mobile Development in Visual Studio | Microsoft Learn

Yes you are right, I after installing the Mobile development with C++ Package for Visual Studio I was able to choose to create a Dynamic Shared Library (Android).
Using the resulting .so file from the build worked for me :+1:.

Thanks alot!

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.