Android 64-bit .so DLL file not found error

Hello,

I am trying to update an older plugin to work for Android 64 bit builds, and am running into problems. Namely, I am trying to update the “OpenCV + Unity” plugin, and I have already created a 64bit “libOpenCvSharpExtern.so” file by editing the repo here.

The file I have created is available here. I have checked using MSYS2 “file” commands that the file is a 64bit build file, which all seems to be correct, as far as I can tell. I have then added the file to “/Assets/…/Plugins/Android/arm64-v8a/libOpenCvSharpExtern.so”.

By my understanding, this should work. Instead, the .so file is not added to my APK and the DLL cannot be found, resulting in the error:

<i>AndroidPlayer(ADB@127.0.0.1:34999)</i> DllNotFoundException: Unable to load DLL 'OpenCvSharpExtern': The specified module could not be found.
  at OpenCvSharp.NativeMethods.core_Mat_sizeof () [0x00000] in <00000000000000000000000000000000>:0 
  at OpenCvSharp.NativeMethods.TryPInvoke () [0x00000] in <00000000000000000000000000000000>:0 
  at OpenCvSharp.NativeMethods..cctor () [0x00000] in <00000000000000000000000000000000>:0 
  at OpenCvSharp.OCRHMMDecoder+ClassifierCallback..ctor (System.String fileName, OpenCvSharp.CvText+OCRClassifierType type) [0x00000] in <00000000000000000000000000000000>:0 
  at OpenCvSharp.Demo.AlphabetOCR..ctor (System.Byte[] model) [0x00000] in <00000000000000000000000000000000>:0 
  at molAR.Start () [0x00000] in <00000000000000000000000000000000>:0 
Rethrow as OpenCvSharpException: Unable to load DLL 'OpenCvSharpExtern': The specified module could not be found.
*** An exception has occurred because of P/Invoke. ***
Please check the following:
(1) OpenCV's DLL files exist in the same directory as the executable file.
(2) Visual C++ Redistributable Package has been installed.
(3) The target platform(x86/x64) of OpenCV's DLL files and OpenCvSharp is the same as your project's.

System.DllNotFoundException: Unable to load DLL 'OpenCvSharpExtern': The specified module could not be found.
  at OpenCvSharp.NativeMethods.core_Mat_sizeof () [0x00000] in <00000000000000000000000000000000>:0 
  at OpenCvSharp.NativeMethods.TryPInvoke () [0x00000] in <00000000000000000000000000000000>:0 
  at OpenCvSharp.NativeMethods..cctor () [0x00000] in <00000000000000000000000000000000>:0 
  at OpenCvSharp.OCRHMMDecoder+ClassifierCallback..ctor (System.String fileName, OpenCvSharp.CvText+OCRClassifierType type) [0x00000] in <00000000000000000000000000000000>:0 
  at OpenCvSharp.Demo.AlphabetOCR..ctor (System.Byte[] model) [0x00000] in <00000000000000000000000000000000>:0 
  at myCode.Start () [0x00000] in <00000000000000000000000000000000>:0 
  at OpenCvSharp.NativeMethods.TryPInvoke () [0x00000] in <00000000000000000000000000000000>:0 
  at OpenCvSharp.NativeMethods..cctor () [0x00000] in <00000000000000000000000000000000>:0 
  at OpenCvSharp.OCRHMMDecoder+ClassifierCallback..ctor (System.String fileName, OpenCvSharp.CvText+OCRClassifierType type) [0x00000] in <00000000000000000000000000000000>:0 
  at OpenCvSharp.Demo.AlphabetOCR..ctor (System.Byte[] model) [0x00000] in <00000000000000000000000000000000>:0 
  at myCode.Start () [0x00000] in <00000000000000000000000000000000>:0 
Rethrow as TypeInitializationException: The type initializer for 'OpenCvSharp.NativeMethods' threw an exception.
  at OpenCvSharp.OCRHMMDecoder+ClassifierCallback..ctor (System.String fileName, OpenCvSharp.CvText+OCRClassifierType type) [0x00000] in <00000000000000000000000000000000>:0 
  at OpenCvSharp.Demo.AlphabetOCR..ctor (System.Byte[] model) [0x00000] in <00000000000000000000000000000000>:0 
  at myCode.Start () [0x00000] in <00000000000000000000000000000000>:0 
 
(Filename: currently not available on il2cpp Line: -1)

I have also tried to create a linker file based on another answer on this site, the file is called “link.dll” and has the below contents, which are quite possibly wrong:

    <linker>
           <assembly fullname="libOpenCvSharpExtern" preserve="all"/>
    </linker>

What am I doing wrong here? I am quite new to all this and likely doing something silly.

Thank you in advance for your help!

Turns out I made a very silly mistake. You need to actually go into the Unity editor, navigate to the file in your project, and instruct Unity what platform your .so file needs to target. In my case, I needed to select the “Android 64bit” option, and then the file worked.

Problem solved.

Hi, ninjafishnz
This is Rick
Could you tell me how to create libOpenCvsharpExtern.so file by editing this repo? GitHub - Gobra/OpenCV-Unity: OpenCV plus Unity
I am looking forward to hearing from you soon!
Best Regards.