简体   繁体   English

在Android Studio上使用NDK构建本机OpenCV

[英]Building native openCV with NDK on android studio

I am making a C++ project which uses openCV and I wish to build it on android studio using android NDK support. 我正在制作一个使用openCV的C ++项目,并且希望使用android NDK支持在android studio上构建它。
On doing so I found out that only the experimental version of gradle supports NDK. 这样做时,我发现只有gradle的实验版本支持NDK。 I am currently using version 0.2.1 of gradle. 我目前正在使用gradle的0.2.1版本。 I imported opencv as a module and copied the libraries to jniLibs folder under src/main/ 我将opencv作为模块导入,并将库复制到src / main /下的jniLibs文件夹中

I tried to compile it but I got certain errors like undefined reference to some functions in parallel.cpp of libopencv_core.a . 我尝试编译它,但是遇到了某些错误,例如libopencv_core.a的parallel.cpp中对某些函数的未定义引用。 They were resolved on importing the third party library : libtbb.a 他们解决了导入第三方库的问题:libtbb.a

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"

here is my build.gradle : 这是我的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')
}

I am stuck. 我被困住了。 Please help. 请帮忙。

I added all the 3rd party libraries too and this allowed to compile for arm. 我也添加了所有第3方库,因此可以进行编译。 To be fair, I also added the 3rd party libraries in jniLibs, just to avoid changing the path as you did up there. 公平地说,我还在jniLibs中添加了第3方库,只是为了避免像在此处那样更改路径。 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"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM