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.
QUESTION:
if I have unity compiling on ndk19 should I setup the build_sdk.py to build the android version targeting on ndk 19? or if I target to 18 (–config=ndk-18-api-level-21.config.py) 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\build_sdk.py” “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” --config=ndk-18.config.py
In the end I can properly compile the android version I get:
build\OpenCV-android-sdk\sdk\native\libs\armeabi-v7a\libopencv_java4.so
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):
myunityproject\Assets\OpenCVForUnity\Plugins\Android\libs\armeabi-v7a\libopencv_java4.so
also the same with the extra Unity libopencvforunity.so:
myunityproject\Assets\OpenCVForUnity\Extra\dll_version\Android\libs\armeabi-v7a\libopencvforunity.so
To:
myunityproject\Assets\OpenCVForUnity\Plugins\Android\libs\armeabi-v7a\libopencv_java4.so
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 ).
Android
Build the Android SDK with “opencv/platforms/android/build_sdk.py”. ( APP_STL
:= c++_static)
python …/opencv/platforms/android/build_sdk.py …/build …/opencv
–ndk_path=C://android-ndk --sdk_path=C://android-sdk
–extra_modules_path=…/opencv_contrib/modules
–config=ndk-18-api-level-21.config.py
Copy the output file ( native\libs\arm64-v8a\libopencv_java4.so ) to
“OpenCVForUnity\Plugins\Android\libs\arm64-v8a\”. Copy the output files (
native\libs\arm64-v8a\libopencv_java4.so ) to
“OpenCVForUnity\Plugins\Android\libs\armeabi-v7a\”. Copy the output files (
native\libs\x86\libopencv_java4.so ) to
“OpenCVForUnity\Plugins\Android\libs\x86\”.
Copy “OpenCVForUnity\Extra\dll_version\Android\libs\” to
“OpenCVForUnity\Plugins\Android\libs\”.
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)
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 build-sdk.py internally:
cmd.append("-DBUILD_ZLIB=‘ON’")