Reputation: 325
I have an android project using OpenCV and I need use OpenCV from native C++ code. But I have problem, to config cmake to link libraries. I have no knowledge about cmake, nor with gradle.
I found some pieces of advice and tried to write CMakeLists.txt on my own, but I wasn't successful. Currently, my CMakeLists.txt looks like:
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_VERBOSE_MAKEFILE on)
add_library(cpp_native_code SHARED src/main/cpp/jni_interface.cpp)
# find all other source files
file ( GLOB cpp_code_files src/main/cpp/*.cpp src/main/cpp/*.hpp )
# add then to project
target_sources(cpp_native_code PUBLIC ${cpp_code_files})
find_library(log-lib log)
target_link_libraries(cpp_native_code ${log-lib})
set(path_to_opencv C:/Programs/OpenCV_Android_SDK)
include_directories(${path_to_opencv}/sdk/native/jni/include)
add_library( lib_opencv SHARED IMPORTED )
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so)
target_link_libraries( cpp_native_code lib_opencv )
When I try to run my project, I get this error:
Error:error: '../../../../src/main/jniLibs/arm64-v8a/libopencv_java3.so',
needed by '../../../../build/intermediates/cmake/debug/obj/arm64-
v8a/libcpp_native_code.so', missing and no known rule to make it
I am using OpenCV 3.3.0. If needed, I provide screenshot of my project structure here. OpenCV works when used from android directly.
Please, could you someone advise me, whan am I doing wrong? Or if there is some information, I didn't write and which is important.
Thanks, for your advice.
Upvotes: 3
Views: 3806
Reputation: 161
Look at this project
Note, this is not my project, I didn't test it.
Upvotes: 1