首先新建Native C++工程,这里就不多说了。
1. 添加so库及include文件夹到相应的位置
OpenCv官网
官方下载较慢,这里提供本文所需一些文件
2. build.gradle配置
arguments \"-DANDROID_STL=c++_shared\"
sourceSets {main {//将libs中的so文件都打包。jniLibs.srcDirs = [\'libs\']}}
3. CMakeLists.txt
- Android CMake 常用命令和变量
cmake_minimum_required(VERSION 3.4.1)#引入 include文件夹include_directories(include)#定义全局 all变量file(GLOB all ${CMAKE_SOURCE_DIR}/*.cpp ${CMAKE_SOURCE_DIR}/*.c)add_library( toOpenCv SHARED ${all} )add_library( lib_opencv SHARED IMPORTED)set_target_properties(lib_opencvPROPERTIESIMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/../jniLibs/${ANDROID_ABI}/libopencv_java4.so)find_library( log-lib log )find_library(jnigraphics-lib jnigraphics )target_link_libraries(toOpenCvlib_opencv${jnigraphics-lib}${log-lib} )