我将原生OpenCV 3.0包含在Android Studio中,如here所述。
Android.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)
Application.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
根据谷歌的说法,这可能是一些语法问题,但我无法解决它。