使用NDK在android studio上构建本地openCV
我正在做一个C ++项目,它使用openCV,我希望在android studio上使用android NDK支持构建它。
在这样做时,我发现只有gradle的实验版本支持NDK。我目前使用版本0.2.1的gradle。我导入opencv作为一个模块,并将库复制到jniLibs文件夹下的src / main /
I am making a C++ project which uses openCV and I wish to build it on android studio using android NDK support.
On doing so I found out that only the experimental version of gradle supports NDK. I am currently using version 0.2.1 of gradle. I imported opencv as a module and copied the libraries to jniLibs folder under src/main/
我试图编译它,但我得到一些错误,如未定义的引用一些函数parallel.cpp的libopencv_core.a。
他们在导入第三方库时解决:libtbb.a
I tried to compile it but I got certain errors like undefined reference to some functions in parallel.cpp of libopencv_core.a . They were resolved on importing the third party library : libtbb.a
但是在运行它时我遇到了以下错误: java.lang.UnsatisfiedLinkError:dlopen失败:找不到由libtracking_bits.so引用的符号__gnu_thumb1_case_si
But on running it I got the following errors:java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "__gnu_thumb1_case_si" referenced by "libtracking_bits.so"
是我的build.gradle:
here is my build.gradle :
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 21
buildToolsVersion = "22.0.1"
defaultConfig.with {
applicationId = "com.example.vlc.receiver"
minSdkVersion.apiLevel = 16
targetSdkVersion.apiLevel = 21
versionCode = 1
versionName = "1.0"
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
debug {
minifyEnabled = false
}
}
android.ndk {
moduleName = "tracking_bits"
cppFlags += "-fexceptions"
cppFlags += "-frtti"
cppFlags += "-I${file("OpenCV-android-sdk/sdk/native/jni/include")}".toString()
cppFlags += "-I${file("OpenCV-android-sdk/sdk/native/jni/include/opencv")}".toString()
ldLibs += ["android", "EGL", "GLESv2", "dl", "log", "z"]// , "ibopencv_core"
stl = "gnustl_shared"
}
android.productFlavors {
create("arm") {
ndk.with {
abiFilters += "armeabi"
File curDir = file('./')
curDir = file(curDir.absolutePath)
String libsDir = curDir.absolutePath+"\\src\\main\\jniLibs\\armeabi\\" //"-L" +
ldLibs += libsDir + "libopencv_calib3d.a"
ldLibs += libsDir + "libopencv_core.a"
ldLibs += libsDir + "libopencv_features2d.a"
ldLibs += libsDir + "libopencv_flann.a"
ldLibs += libsDir + "libopencv_hal.a"
ldLibs += libsDir + "libopencv_highgui.a"
ldLibs += libsDir + "libopencv_imgcodecs.a"
ldLibs += libsDir + "libopencv_imgproc.a"
ldLibs += libsDir + "libopencv_java3.so"
ldLibs += libsDir + "libopencv_ml.a"
ldLibs += libsDir + "libopencv_objdetect.a"
ldLibs += libsDir + "libopencv_photo.a"
ldLibs += libsDir + "libopencv_shape.a"
ldLibs += libsDir + "libopencv_stitching.a"
ldLibs += libsDir + "libopencv_superres.a"
ldLibs += libsDir + "libopencv_ts.a"
ldLibs += libsDir + "libopencv_video.a"
ldLibs += libsDir + "libopencv_videoio.a"
ldLibs += libsDir + "libopencv_videostab.a"
ldLibs += "OpenCV-android-sdk\\sdk\\native\\3rdparty\\libs\\armeabi\\libtbb.a"
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.1'
compile project(':openCVLibrary300')
}
我被卡住了。请帮助。
我添加了所有第三方库,这允许编译arm。公平地说,我还在jniLibs中添加了第三方库,只是为了避免改变你在那里的路径。
I added all the 3rd party libraries too and this allowed to compile for arm. To be fair, I also added the 3rd party libraries in jniLibs, just to avoid changing the path as you did up there. Otherwise, I have exactly the same configuration as you, to the point that I copied and pasted your file in a previous stage.
ldLibs += libsDir + "libIlmImf.a"
ldLibs += libsDir + "liblibjpeg.a"
ldLibs += libsDir + "liblibjasper.a"
ldLibs += libsDir +"liblibpng.a"
ldLibs += libsDir +"liblibwebp.a"