1

如here所述,我将本机 OpenCV 3.0 包含到 Android Studio 中。

安卓.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

#opencv 
OPENCVROOT:= D:/OpenCV-android-sdk_3 
OPENCV_CAMERA_MODULES:=on 
OPENCV_INSTALL_MODULES:=on 
OPENCV_LIB_TYPE:=STATIC 
include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk 
include $(OPENCV_MK_PATH)

LOCAL_C_INCLUDES += $(LOCAL_PATH)

LOCAL_SRC_FILES := main.cpp 
LOCAL_LDLIBS += -llog -ldl 
LOCAL_MODULE := hello

include $(BUILD_SHARED_LIBRARY)

应用程序.mk:

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := all
APP_PLATFORM := android-19

对于 NDK 编译,我使用以下参数创建了一个调用 ndk-build.cmd 的外部工具:

NDK_PROJECT_PATH=$ModuleFileDir$/build/intermediates/ndk NDK_LIBS_OUT=$ModuleFileDir$/src/main/jniLibs NDK_APPLICATION_MK=$ModuleFileDir$/src/main/jni/Application.mk APP_BUILD_SCRIPT=$ModuleFileDir$/src/main/jni/Android.mk V=1

问题:

我仍然不能包含任何 opencv 标头,例如

#include <opencv2/core/core.hpp

它总是保持红色。我阅读了许多其他线程,但找不到解决方案。我错过了什么?

我正在使用 Windows 7 64 位。

提前致谢!

编辑:

我现在将 OpenCV 作为一个模块包含在内,并像这样实现了实验性 gradle:

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

model {
    android {
        compileSdkVersion = 19
        buildToolsVersion = "23.0.2"

        defaultConfig {
            applicationId = "..."
            minSdkVersion = 16
            targetSdkVersion = 19
            versionCode = 1
            versionName = "1.0"

        }
    }

    android.ndk{
        moduleName = "openCVLibrary300"
        ldLibs += ['log']
        cppFlags += "-std=c++11"
        cppFlags += "-fexceptions"
        cppFlags  += "-I${file("D:\\OpenCV-android-sdk_3\\sdk\\native\\jni\\include")}".toString()
        cppFlags  += "-I${file("D:\\OpenCV-android-sdk_3\\sdk\\native\\jni\\include\\opencv")}".toString()



//        ldFlags += linkOpt
        ldLibs += ["android", "EGL", "GLESv2", "dl", "log", "z"]// , "ibopencv_core"
        stl = "gnustl_shared"//"gnustl_static"//"gnustl_shared"//"stlport_static"
    }

    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles += file('proguard-rules.pro')
        }
    }

    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_core.a"
                ldLibs += libsDir + "libopencv_core.a"
                ldLibs += libsDir + "libopencv_highgui.a"
                ldLibs += libsDir + "libopencv_imgproc.a"
                ldLibs += libsDir + "libopencv_ml.a"
                ldLibs += libsDir + "libopencv_ts.a"

            }
        }
        create("armv7") {
            ndk.with {
                abiFilters += "armeabi-v7a"

                File curDir = file('./')
                curDir = file(curDir.absolutePath)
                String libsDir = curDir.absolutePath+"\\src\\main\\jniLibs\\armeabi-v7a\\" //"-L" +

                ldLibs += libsDir + "libopencv_core.a"
                ldLibs += libsDir + "libopencv_core.a"
                ldLibs += libsDir + "libopencv_highgui.a"
                ldLibs += libsDir + "libopencv_imgproc.a"
                ldLibs += libsDir + "libopencv_ml.a"
                ldLibs += libsDir + "libopencv_ts.a"

            }
        }
        create("x86") {
            ndk.with {
                abiFilters += "x86"
            }
        }
        create("mips") {
            ndk.with {
                abiFilters += "mips"
            }
        }
        create("fat") {

        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:19.1.0'
    compile project(':openCVLibrary300')
}

现在我不断收到这个未详细说明的错误:

Error:Cause: com.android.build.gradle.managed.AndroidConfig_Impl

根据谷歌这可能是一些语法问题,但我无法解决它。

4

0 回答 0