I have custom C++ classes which I want to run on my android app. I am successfully binded my C++ files using CMakeLists
. But as my classes uses opencv, I am getting an issue which is obvious
fatal error: 'opencv2/core.hpp' file not found
Then I tried to add opencv library on my android app, downloaded the open cv android sdk and tired to add it on my project. Below is the folder structure
android
-> app
-> opencv2
All the opencv2 c++ files and folders
->folder1
My custom c++ classes which will import opencv2.
The following is my CMakeLists.txt file
cmake_minimum_required(VERSION 3.4.1) # for example
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
PROJECT(tag)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_library( tag_native
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
"./folder1/tag_native.cpp" )
add_library( opencv2
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
"./opencv2/" )
set_target_properties(opencv2 PROPERTIES LINKER_LANGUAGE CXX)
This is the sample of my cpp file
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <iostream>
#include <opencv2/core.hpp>
Everything from c++ compiles well but I am still getting the same issue
* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing process C:\Users\Brainants with arguments {Technology\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\ninja.exe -C E:\Squtag\Squtag Mobile\android\app\.cxx\cmake\debug\armeabi-v7a opencv2 squtag_native}
ninja: Entering directory `E:\Squtag\Squtag Mobile\android\app\.cxx\cmake\debug\armeabi-v7a'
[1/2] Building CXX object CMakeFiles/squtag_native.dir/E_/Squtag/Squtag_Mobile/ios/Runner/Squtag_Native/squtag_native.cpp.o
FAILED: CMakeFiles/squtag_native.dir/E_/Squtag/Squtag_Mobile/ios/Runner/Squtag_Native/squtag_native.cpp.o
C:\Users\BRAINA~1\AppData\Local\Android\Sdk\ndk\210~1.611\TOOLCH~1\llvm\prebuilt\WINDOW~1\bin\CLANG_~1.EXE --target=armv7-none-linux-androideabi24 --gcc-toolchain="C:/Users/Brainants Technology/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64" --sysroot="C:/Users/Brainants Technology/AppData/Local/Android/Sdk/ndk/21.0.6113669/toolchains/llvm/prebuilt/windows-x86_64/sysroot" -Dsqutag_native_EXPORTS -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -Wformat -Werror=format-security -fsanitize=address -fno-omit-frame-pointer -std=c++11 -O0 -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/squtag_native.dir/E_/Squtag/Squtag_Mobile/ios/Runner/Squtag_Native/squtag_native.cpp.o -MF CMakeFiles\squtag_native.dir\E_\Squtag\Squtag_Mobile\ios\Runner\Squtag_Native\squtag_native.cpp.o.d -o CMakeFiles/squtag_native.dir/E_/Squtag/Squtag_Mobile/ios/Runner/Squtag_Native/squtag_native.cpp.o -c "E:/Squtag/Squtag Mobile/ios/Runner/Squtag Native/squtag_native.cpp"
E:/Squtag/Squtag Mobile/ios/Runner/Squtag Native/squtag_native.cpp:6:10: fatal error: 'opencv2/core.hpp' file not found
#include <opencv2/core.hpp>
^~~~~~~~~~~~~~~~~~
1 error generated.
ninja: build stopped: subcommand failed.