build.gradle配置:
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -frtti -fexceptions"
arguments "-DANDROID_STL=c++_shared"
}
}
ndk {
abiFilters 'armeabi-v7a'
}
sourceSets {
main {
jniLibs.srcDirs = ['src/main/jniLibs']
}
}
CMakeLists.txt 配置:
cmake_minimum_required(VERSION 3.4.1)
include_directories(src/main/cpp/inc)
link_directories(${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI})
add_library(
native-lib
SHARED
${CMAKE_SOURCE_DIR}/src/main/cpp/src/native-lib.cpp
)
find_library(
log-lib
log)
target_link_libraries(
native-lib
opencv_java4
${log-lib})