android studio 3.6.3 引入openCV(3.4.3)
安卓新建项目选择 native C++,C++ 14(C++ 11)
一、下载Opencv
二、导入Module
三、配置opencv代码
1.删除 <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" />
2.配置opencv的sdk版本,修改和项目app的一样
四、复制arm64-v8a和armeabi-v7a到项目的libs目录下
五、添加依赖
dependencies {
...
implementation project(path: ':openCVLibrary343')
//将打好jar包,添加到依赖中
implementation fileTree(dir: "$buildDir/native-libs", include: 'native-libs.jar')
}
//以下很重要
//将添加的.so文件,打包成jar
task nativeLibsToJar(type: Jar, description: 'create a jar archive of the native libs') {
destinationDir file("$buildDir/native-libs")
baseName 'native-libs'
from fileTree(dir: 'libs', include: '**/*.so')
into 'lib/'
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn(nativeLibsToJar)
}