我正在尝试使用gradle-experimental:0.6.0-beta5构建一个使用OpenCV 3.0.0的本机应用程序,我的Android Studio版本是v2.1 Preview 1.我已经按照
Android Studio linking OpenCV static libraries
和
Building native openCV with NDK on android studio
声明我将在build.gradle文件中使用的静态库,我已经将第三方库复制到 / src / main / jniLibs / armeabi / 3rdparty / :
def openCVAndroidLibDir = file(project(':app').projectDir).absolutePath + "/src/main/jniLibs"
def openCVAndroidSdkDir = "/home/jxsun/OpenCV-android-sdk/sdk/native/jni/include/opencv2"
model {
repositories {
prebuilt(org.gradle.nativeplatform.PrebuiltLibraries) {
libtiff {
binaries.withType(StaticLibraryBinary) {
staticLibraryFile = file("${openCVAndroidLibDir}/${targetPlatform.getName()}/3rdparty/liblibtiff.a")
}
}
...
tbb {
binaries.withType(StaticLibraryBinary) {
staticLibraryFile = file("${openCVAndroidLibDir}/${targetPlatform.getName()}/3rdparty/libtbb.a")
}
}
opencv_hal {
headers.srcDir "${openCVAndroidSdkDir}"
binaries.withType(StaticLibraryBinary) {
staticLibraryFile = file("${openCVAndroidLibDir}/${targetPlatform.getName()}/libopencv_hal.a")
}
}
opencv_core {
headers.srcDir "${openCVAndroidSdkDir}"
binaries.withType(StaticLibraryBinary) {
staticLibraryFile = file("${openCVAndroidLibDir}/${targetPlatform.getName()}/libopencv_core.a")
}
}
...
opencv_videostab {
headers.srcDir "${openCVAndroidSdkDir}"
binaries.withType(StaticLibraryBinary) {
staticLibraryFile = file("${openCVAndroidLibDir}/${targetPlatform.getName()}/libopencv_videostab.a")
}
}
}
}
android.sources {
main {
jni {
dependencies {
library "IlmImf" linkage "static"
...
library "tbb" linkage "static"
library "opencv_core" linkage "static"
...
library "opencv_videostab" linkage "static"
library "opencv_hal" linkage "static"
}
}
}
}
android.ndk {
moduleName = "test"
cppFlags.add("-std=c++11")
cppFlags.add("-fexceptions")
cppFlags.add("-frtti")
cppFlags.add("-I${file("/home/jxsun/OpenCV-android-sdk/sdk/native/jni/include")}".toString())
cppFlags.add("-I${file("/home/jxsun/OpenCV-android-sdk/sdk/native/jni/include/opencv")}".toString())
cppFlags.add("-I${file("/home/jxsun/OpenCV-android-sdk/sdk/native/jni/include/opencv2")}".toString())
abiFilters.add("armeabi")
ldLibs.addAll(["android", "EGL", "GLESv2", "dl", "log", "z"])
stl = "gnustl_shared"
platformVersion = 21
}
但不幸的是,我仍然收到很多关于tbb的未定义的引用错误:
/home/jxsun/StudioProjects/Test/app/src/main/jniLibs/armeabi/libopencv_core.a(parallel.cpp.o):parallel.cpp:function tbb::interface6::internal::start_for<tbb::blocked_range<int>, (anonymous namespace)::ProxyLoopBody, tbb::auto_partitioner const>::~start_for(): error: undefined reference to 'vtable for tbb::task'
似乎libtbb.a仍然无法解决,即使我把它放在prebuilt和dependencies块中。 我该如何解决这个问题?
答案 0 :(得分:2)
我已经改变了@AlexCohn建议的 jni.dependencies 的顺序,它现在就像一个魅力。所以我想在这里分享我的链接订单,以了解谁可能面临一些问题:D
android.sources {
main {
jni {
dependencies {
/*
* OpenCV
*/
library "opencv_flann" linkage "static"
library "opencv_imgproc" linkage "static"
library "opencv_ml" linkage "static"
library "opencv_photo" linkage "static"
library "opencv_video" linkage "static"
library "opencv_imgcodecs" linkage "static"
library "opencv_shape" linkage "static"
library "opencv_videoio" linkage "static"
library "opencv_highgui" linkage "static"
library "opencv_objdetect" linkage "static"
library "opencv_superres" linkage "static"
library "opencv_ts" linkage "static"
library "opencv_features2d" linkage "static"
library "opencv_calib3d" linkage "static"
library "opencv_stitching" linkage "static"
library "opencv_videostab" linkage "static"
library "opencv_core" linkage "static"
library "opencv_hal" linkage "static"
/*
* OpenCV 3rd parties
*/
library "IlmImf" linkage "static"
library "libjpeg" linkage "static"
library "libjasper" linkage "static"
library "libpng" linkage "static"
library "libwebp" linkage "static"
library "libtiff" linkage "static"
library "tbb" linkage "static"
}
}
}
}