Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/162.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关于在gradle中链接外部本机库(opencv c++) 我正在创建一个使用OpenCV C++代码的项目。到目前为止,我只能在maven central中找到托管在以下位置的java可执行文件:- http://mvnrepository.com/artifact/nu.pattern/opencv/2.4.9-4_C++_Maven_Opencv_Gradle - Fatal编程技术网

关于在gradle中链接外部本机库(opencv c++) 我正在创建一个使用OpenCV C++代码的项目。到目前为止,我只能在maven central中找到托管在以下位置的java可执行文件:- http://mvnrepository.com/artifact/nu.pattern/opencv/2.4.9-4

关于在gradle中链接外部本机库(opencv c++) 我正在创建一个使用OpenCV C++代码的项目。到目前为止,我只能在maven central中找到托管在以下位置的java可执行文件:- http://mvnrepository.com/artifact/nu.pattern/opencv/2.4.9-4,c++,maven,opencv,gradle,C++,Maven,Opencv,Gradle,所以我在我的系统上安装了opencv,并开始在我的项目中使用它。为了使用opencv头编译我的项目,我在build.gradle脚本中引入了以下内容:- // C++ specific build configurations // Acquiring environment variables def opencvhome = System.getenv("OPENCV_HOME") def opencvinclude = opencvhome + "\\include" model {

所以我在我的系统上安装了opencv,并开始在我的项目中使用它。为了使用opencv头编译我的项目,我在build.gradle脚本中引入了以下内容:-

// C++ specific build configurations

// Acquiring environment variables
def opencvhome = System.getenv("OPENCV_HOME")

def opencvinclude = opencvhome + "\\include"

model {
    components {
        main(NativeLibrarySpec) {
            sources {
                cpp {
                    source {
                        srcDirs "src/main/cpp"
                        include "**/*.cpp"
                    }
                    exportedHeaders {
                        srcDirs "src/main/include", opencvinclude
                    }
                 }
            }
        }
    }
}
这是为了包含必要的标题。注意opencvinclude部分作为一个环境变量,我在运行gradle构建之前将其设置为安装位置

现在我的问题是如何添加opencv的其他链接依赖项

https://docs.gradle.org/current/userguide/nativeBinaries.html

我查阅了上述文件。它只涵盖那些本身就是gradle项目的依赖项。但是OpenCV C++不是一个简单的项目。有人能帮我解决这个问题吗?

请参阅build.gradle中的摘录,它配置了与opencv库的静态链接

apply plugin: 'com.android.model.application'

model {

    compileOptions.with {
        sourceCompatibility = JavaVersion.VERSION_1_7
        targetCompatibility = JavaVersion.VERSION_1_7
    }

    android {
        compileSdkVersion = 22
        buildToolsVersion = "22.0.1"

        defaultConfig.with {
            applicationId = "com.example.oleg.myapplication"
            minSdkVersion.apiLevel = 18
            targetSdkVersion.apiLevel = 22
            versionCode = 1
            versionName = "1.0"
            testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
        }

    }

    android.ndk {
        moduleName = "fastcvUtils"

        //abiFilters += ["armeabi", "armeabi-v7a", "x86"]
        abiFilters += "armeabi-v7a"

        // Link with static OpenCV libraries: the order is important!
        // The following order taken from OpenCV.mk
        def opencv_modules = ["shape", "stitching", "objdetect", "superres", "videostab", "calib3d", "features2d", "highgui", "videoio", "imgcodecs", "video", "photo", "ml", "imgproc", "flann", "core", "hal"]

        ldLibs += ["log","stdc++","dl", "z"]

        abiFilters.each { targetAbi ->
            println targetAbi

            opencv_modules.each{ module ->
                ldLibs += file(projectDir).absolutePath + "/src/main/jniLibs/" + targetAbi + "/libopencv_" + module + ".a"
            }
        }

        cppFlags   += "-Werror"
        cppFlags   += "--debug"
        cppFlags   += "-frtti"
        cppFlags   += "-fexceptions"
        cppFlags += "-I/Users/Oleg/Downloads/OpenCV-android-sdk/sdk/native/jni/include"


        ldLibs += file(projectDir).absolutePath+"/src/main/jniLibs/armeabi-v7a/libtbb.a"

        stl = "gnustl_static"

    }

    android.buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles += file('proguard-android.pro')
            isJniDebuggable = true
            isDebuggable = true
        }

        debug {
            isJniDebuggable = true
            isDebuggable = true
        }
    }

    android.productFlavors {

        create("arm") {
            ndk.with {

                abiFilters += "armeabi"
                println "*** building for arm"
            }

        }

        create("armv7") {
            ndk.with {

                abiFilters += "armeabi-v7a"
                println "*** building for armv7"
            }

        }

        create("x86") {
            ndk.with {
                abiFilters += "x86"
                println "*** building for x86"
            }
        }
    }

}
它假定.a库是从OpenCV SDK复制到jniLibs文件夹中的