Home > Software engineering >  CMake error while adding opencv 4.5.2 into my android studio project
CMake error while adding opencv 4.5.2 into my android studio project

Time:04-02

I was trying to add opencv 4.5.2 into my android studio project. But I am getting errors when I try to run the application. There was no error before that.

Steps that I followed to add opencv:

  1. File -> New -> Import Module and then I selected the sdk folder that was inside the extracted folder of opencv-4.5.2-android-sdk (that I downloaded from opencv.org/releases/) and I gave it name openCVLibrary452 and then I clicked on finish.

  2. File -> Project Structure -> Add Dependency and then I selected openCVLibrary452 from the list and clicked Apply and Ok.

Now I added below line inside my MainActivity onCreate()

Log.e("TAG", "OpenCV initialized : "  OpenCVLoader.initDebug());

When I try to run the app this is the error I get:

[CXX1405] error when building with cmake using F:\StudioProjects\KingScanner\openCVLibrary452\libcxx_helper\CMakeLists.txt: Build command failed.
Error while executing process E:\Android_sdk\cmake\3.18.1\bin\cmake.exe with arguments {-HF:\StudioProjects\KingScanner\openCVLibrary452\libcxx_helper -DCMAKE_SYSTEM_NAME=Android -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_SYSTEM_VERSION=21 -DANDROID_PLATFORM=android-21 -DANDROID_ABI=arm64-v8a -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a -DANDROID_NDK=E:\Android_sdk\ndk\21.4.7075529 -DCMAKE_ANDROID_NDK=E:\Android_sdk\ndk\21.4.7075529 -DCMAKE_TOOLCHAIN_FILE=E:\Android_sdk\ndk\21.4.7075529\build\cmake\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=E:\Android_sdk\cmake\3.18.1\bin\ninja.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=F:\StudioProjects\KingScanner\openCVLibrary452\build\intermediates\cxx\Debug\6n761z2d\obj\arm64-v8a -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=F:\StudioProjects\KingScanner\openCVLibrary452\build\intermediates\cxx\Debug\6n761z2d\obj\arm64-v8a -DCMAKE_BUILD_TYPE=Debug -BF:\StudioProjects\KingScanner\openCVLibrary452\.cxx\Debug\6n761z2d\arm64-v8a -GNinja -DANDROID_STL=c  _shared}

This is my first time adding opencv to my project. Can you please tell me what am I missing here.

Any help would be much appreciated. Thank you.

CodePudding user response:

It doesn't fix the issue with your compiler, but if you just want to use OpenCV you can put this dependency in your build.gradle:

implementation 'ai.eye2you:opencv-android:4.5.2'

And then just initialize it with your code or with System.loadLibrary("opencv_java4").

  • Related