dllnotfoundexception library not found when using .dll files in unity on an android build

219 Views Asked by At

I am trying to use a c++ library in a .dll files in my Unity project that is build to android. If i am running it in the editor it works as expected. If i build it on android and run it, logcat says:

"DllNotFoundException: Unable to load DLL 'ardll'. Tried the load the following dynamic libraries: Unable to load dynamic library 'ardll' because of 'Failed to open the requested dynamic library (0x06000000) dlerror() = dlopen failed: library "ardll" not found"

I did some digging and found some posts about this topic. Namely these:

Using dll-Library in Unity3D for Android Build https://discussions.unity.com/t/how-do-i-include-added-dlls-to-a-android-apk-build/133343 https://forum.unity.com/threads/unity-dll-plugins-for-android.892189/

A common answer i see is that the plugin is being stripped and i need a link.xml to prevent that. i followed all the steps mentioned in the posts and read these manual pages:

https://docs.unity3d.com/Manual/ManagedCodeStripping.html https://docs.unity3d.com/Manual/unity-linker.html

But i still get this error message and i have no idea what i am doing wrong. For context here is what i did exactly (this is a small sample project just to get the basics running):

  1. Create an empty 3d project
  2. i went to project settings > player > android > Configuration and set scripting backend to IL2CPP and ticked ARMv7 and ARMv64 as the target architectures. My Settings
  3. i added the ardll.dll plugin file inside the Assets/Plugin folder (this is a test library which does nothing besides giving me a number). These are the unity settings for this platform: The inspector of the puglin (Setting the platforms to just android or ticking the "load on startup" box did not solve this problem)
  4. i created an empty file, called it link.xml and put it in the same folder as the dll. The link.xml file only contains this:
<linker>
   <assembly fullname="ardll" preserve="all"/>
</linker>
  1. i created a small script that just tries calling the method in the dll and tells me if it got the number. i call it by doing this:
[DllImport("ardll", EntryPoint = "getTransferNr")]
public static extern int getTransferNr();

The Android device i am using is a LG G8s Thinq running android 12. Everything works fine in the editor but on android it throws the error from above. I use logcat the log the error messages. i have no idea what i am doing wrong and appreciate any help.

Thank you already for your time.

0

There are 0 best solutions below