我想通過使用gradle-experimental:0.6.0-beta5構建一個OpenCV 3.0.0的本機應用程序,而我的Android Studio版本是v2.1預覽1.我已按照
Android Studio linking OpenCV static libraries
和
Building native openCV with NDK on android studio
提供申報我會在的build.gradle文件中使用靜態庫的方法,我已經複製第三方庫/src目錄/ main/jniLibs/armeabi/3rdparty/:OpenCV4Android與Gradle實驗的鏈接錯誤:0.6.0-beta5
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仍不能得到解決,即使我已經把它的預構建和依賴塊。 我應該如何解決這個問題?
對於靜態預建庫,在使用'ldLibs' * VS *'nativeplatform.PrebuiltLibraries'沒有缺點。無論如何,** tbb **必須是列表中的最後一個,因此可能更改** jni.dependencies **的順序可以產生差異 –
謝謝@AlexCohn。我重新排列了依賴關係的順序,它現在可以工作了! – jxsun