1

我正在制作一个使用 openCV 的 C++ 项目,我希望使用 android NDK 支持在 android studio 上构建它。
这样做我发现只有 gradle 的实验版本支持 NDK。我目前正在使用 0.2.1 版的 gradle。我将 opencv 作为模块导入,并将库复制到 src/main/ 下的 jniLibs 文件夹

我试图编译它,但我遇到了某些错误,例如对 libopencv_core.a 的 parallel.cpp 中某些函数的未定义引用。他们在导入第三方库时得到了解决:libtbb.a

但是在运行它时,我得到了以下错误:
java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "__gnu_thumb1_case_si" referenced by "libtracking_bits.so"

这是我的 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')
}

我被困住了。请帮忙。

4

1 回答 1

0

我也添加了所有 3rd 方库,这允许为 arm 编译。公平地说,我还在 jniLibs 中添加了 3rd 方库,只是为了避免像你在那里所做的那样改变路径。否则,我的配置与您完全相同,以至于我在前一阶段复制并粘贴了您的文件。

        ldLibs += libsDir + "libIlmImf.a"
        ldLibs += libsDir +  "liblibjpeg.a"
        ldLibs += libsDir + "liblibjasper.a"
        ldLibs += libsDir +"liblibpng.a"
        ldLibs += libsDir +"liblibwebp.a"
于 2015-09-27T12:34:14.730 回答