Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question DllNotFound for .dll file in Android build

Discussion in 'Android' started by joostbos, Sep 8, 2023.

  1. joostbos

    joostbos

    Joined:
    Feb 4, 2015
    Posts:
    60
    I an using an external software kit that comes with a .dll file. I have set my build target to Android and when I run my project in the Editor it works fine, but when I build and run on my Android phone I keep getting a dll not found exception.

    I have been searching for days, but every post that covers this talks about .aar or .so files.

    I have tried setting the plugin to All platforms and to only Android, but that made no difference. Ticked 'Load on startup' but that also did not help.
    I have set the scripting backend to IL2CPP and tried both API Compatibility levels (.NET 2.1 and .Net Framework), that also did not help.
    I changed the location of the dll from the folder of the external plugin to /Assets/Plugins/Android but again no change.
    I created a link.xml file as described on this manual page https://docs.unity3d.com/Manual/ManagedCodeStripping.html but also no change. But the manual page does not describe how to get the fullname of a dll, so maybe I used the wrong name. I tried the filename without the .dll extension, a camel case variant of it where I replaced underscores and capitalized the word after the underscore and I tried the name I see in the inspector, which has a capital letter at the beginning and has a space in it. Nothing worked.
    In Visual Studio I see that for the dll file the properties say Build Action: None and Copy to Output Directory: Do not copy. Tried changing those to Compile and Copy Always, but still no change.

    [Edit] I am using Unity 2022.3.2f1

    So I hope someone can help me get this working.

    Thanks!
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    4,109
    What is that software and DLL? Do they support the Android platform? If so, they would usually provide a specific library (typically .a or .so extension) for that.

    Third party DLLs do not automatically work cross-platform within Unity. The provider needs to mention compatibility with Unity and what platforms their software works on. If either Unity or platform compatibility is not specified, you should ask their support and unless stated otherwise, you have to assume it is not compatible.

    If you know or learn that the DLL was NOT written in C#/.NET (but rather C/C++) then using that DLL outside of the platform it was built for (usually Windows) will not work.

    Even if the DLL was built with C# and .NET it could still be incompatible because it may target an incompatible .NET version or it may make use of .NET features not supported by Unity's Mono framework or the target platform.
     
    Last edited: Sep 8, 2023
  3. joostbos

    joostbos

    Joined:
    Feb 4, 2015
    Posts:
    60
    Thanks for the clarification. Yes, they do provide an Android version of their development kit as well. Since they do not provide a ready-to-use Unity plugin and because I'm not very strong in Android development, I asked a student to try this out for me and apparently he used the Windows development kit. The student is working on other stuff, so I was hoping I could get this to work, since in Unity I can select the Android platform for the dll.

    I'll bite the bullet :) and dive into the Android development kit and try to get that to work.