OpenCVFor Unity / android Dynamic Lib gives DllNotFoundException

I compiled the android version of OpenCV (opencv4.5.3) and for my surprise I got the error:

Autoconnected Player DllNotFoundException: Unable to load DLL ‘opencvforunity’: The specified module could not be found.

I’m under ARMv7, I also tested ARM64 and didn’t work

It worked on Windows standalone/editor but for unity/android it doesnt.


if I have unity compiling on ndk19 should I setup the to build the android version targeting on ndk 19? or if I target to 18 (– it will be compatible with the ndk19 from unity?

For the compilation I’m using: ndk\19.2.5345600

I’m using this command line to compile:
python “C:\Users\muser.chav\Downloads\opencv4.5.3\opencv-4.53\platforms\android\” “C:\Users\muser.chav\Downloads\opencv4.5.3\buildandroid2” “C:\Users\muser.chav\Downloads\opencv4.5.3\opencv-4.53” --ndk_path=“C:\Users\muser.chav\AppData\Local\Android\Sdk\ndk\19.2.5345600” --sdk_path=“C:\Users\muser.chav\AppData\Local\Android\Sdk” --extra_modules_path=“C:\Users\muser.chav\Downloads\opencv4.5.3\opencv_contrib-4.53\modules”

In the end I can properly compile the android version I get:
I copy this file to the Plugins folder of my project (and inside unity I import it and on the inspector I set it as a ARMv7 lib):

also the same with the extra Unity

I’ve made the steps on the Readme.pdf but it doesnt work it keeps giving me DllNotFoundExceptio the steps are these:

How to use OpenCV Dynamic Link Library with customized build settings :
● Download OpenCV 4.5.3 repository ( git: opencv, opencv-contrib ).

  1. Build the Android SDK with “opencv/platforms/android/”. ( APP_STL
    := c++_static)
    python …/opencv/platforms/android/ …/build …/opencv
    –ndk_path=C://android-ndk --sdk_path=C://android-sdk
  2. Copy the output file ( native\libs\arm64-v8a\ ) to
    “OpenCVForUnity\Plugins\Android\libs\arm64-v8a\”. Copy the output files (
    native\libs\arm64-v8a\ ) to
    “OpenCVForUnity\Plugins\Android\libs\armeabi-v7a\”. Copy the output files (
    native\libs\x86\ ) to
  3. Copy “OpenCVForUnity\Extra\dll_version\Android\libs\” to

Is OpenCVFor Unity dynamic dll custom compilation compatible with the ndk that comes with Unity

e.g. Ndk → Pkg.Revision = 19.0.5232133

I’m getting a lot of compilation errors:

[12/22] Linking CXX shared library jni\armeabi-v7a\
FAILED: jni/armeabi-v7a/
cmd.exe /C "cd . && C:\NDK\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi16 --gcc-toolchain=C:/NDK/toolchains/llvm/prebuilt/windows-x86_
64 -fPIC --sysroot C:/NDK/toolchains/llvm/prebuilt/windows-x86_64/sysroot -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes
 -mfpu=vfpv3-d16 -fno-addrsig -mthumb -mfpu=neon -Wa,--noexecstack -Wformat -Werror=format-security -stdlib=libc++    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dt
or -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow
 -Wsign-promo -Wuninitialized -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Qunused-arguments  -
fvisibility=hidden -fvisibility-inlines-hidden  -Wno-deprecated-declarations -Oz -DNDEBUG   -DNDEBUG  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -Wl,--build-id -Wl,--w
arn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now   -Wl,--as-needed -shared -Wl,-
soname, -o jni\armeabi-v7a\ @CMakeFiles\opencv_java.rsp  && cmd.exe /C "cd /D C:\Users\felipe.chaves\Downloads\opencv4.5.2\buildandroid\o4a\modules
\java\jni && C:\NDK\toolchains\llvm\prebuilt\windows-x86_64\bin\llvm-strip.exe --strip-unneeded C:/Users/felipe.chaves/Downloads/opencv4.5.2/buildandroid/o4a/jni/armeabi-v7a/libopencv""
C:/Users/felipe.chaves/Downloads/opencv4.5.2/opencv-4.52/3rdparty/libpng/pngrutil.c:429: error: undefined reference to 'inflateValidate'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
  File "C:\Users\felipe.chaves\Downloads\opencv4.5.2\opencv-4.52\platforms\android\", line 439, in <module>
    builder.build_library(abi, do_install)
  File "C:\Users\felipe.chaves\Downloads\opencv4.5.2\opencv-4.52\platforms\android\", line 264, in build_library
    execute([self.ninja_path, "-j1" if (self.debug_info or self.debug) else "-j3", "install" if (self.debug_info or self.debug) else "install/strip"])
  File "C:\Users\felipe.chaves\Downloads\opencv4.5.2\opencv-4.52\platforms\android\", line 30, in execute
    raise Fail("Child returned: %s" % retcode)
__main__.Fail: Child returned: 1

that’s in zlib (or is it libz on android ?) it somehow missed it
try to add -D BUILD_ZLIB to your cmake cmdline, this should build it from 3rdparty src, and link it properly
(core and imgcodecs modules depend on that)

(and sorry, no clue about android or unity here, cant really help)

(post deleted by author)

Hi @berak, yes I could compile for the android version 19.0.5232133 (the exact/same that comes with Unity)
I copied the folder to c:\ndk, setup environment variables.
Also copied the sdk that comes with unity and put to c:\sdk, just have to copy the cmake folder that is not present on the Unity version so I also had C:\SDK\cmake\3.6.4111459

but I had to put on the internally:

The build command:
python “C:\Users\felipe.chaves\Downloads\opencv4.5.3\opencv-4.53\platforms\android\” “C:\Users\felipe.chaves\Downloads\opencv4.5.3\buildandroid” “C:\Users\felipe.chaves\Downloads\opencv4.5.3\opencv-4.53” --ndk_path=%ANDROID_NDK_ROOT% --sdk_path=%ANDROID_SDK_ROOT% --extra_modules_path=“C:\Users\felipe.chaves\Downloads\opencv4.5.3\opencv_contrib-4.53\modules” --use_android_buildtools

It was possible to compile and get the

BUT this doesn’t work with unity and android I still keep getting ‘DLLNotFoundException’ after importing it as a ARMv7 lib