我安装了android studio 2.3和NDK&其他必备的东西。我下载android OpenCV库然后我使用这个视频https://www.youtube.com/watch?v=69keQjztg6o在android studio项目中添加OpenCV java库。 现在我想添加和使用原生OpenCV库,但我不知道怎么做以及我应该在CMakeLists.txt和build.gradle(app)中编写什么代码? 请指导我。
这是我的CMakeLists.txt:
cmake_minimum_required(VERSION 3.4.1)
set(EXECUTABLE_OUTPUT_PATH
"${CMAKE_CURRENT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}")
add_library(
native-lib
SHARED
src/main/cpp/native-lib.cpp )
add_library(
nonfree
SHARED
IMPORTED )
set_target_properties(
nonfree
PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libnonfree.so )
include_directories(C:/dev/sdk/OpenCV-android-sdk/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)
set_target_properties(nonfree PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libnonfree.so)
find_library(
log-lib
log )
target_link_libraries(
native-lib
nonfree
lib-opencv
${log-lib} )
这是我的build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "hoseini.seyedali.myapplication"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
cppFlags ""
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',
{
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
compile project(':openCVLibrary320')
}
这是错误:
Error:error: linker command failed with exit code 1 (use -v to see
invocation)