找不到opencv.hpp? Android NDK

时间:2015-04-15 22:31:08

标签: android c++ opencv android-studio android-ndk

我在.so目录中有所有预建的Open CV jniLibs文件,而我有一些使用OpenCV的C++文件。我有以下Android.mkApplication.mk脚本。

Android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= opencv-prebuilt
LOCAL_SRC_FILES:= ../jniLibs/$(TARGET_ARCH_ABI)/libopencv_java.so
LOCAL_EXPORT_C_INCLUDES:= $(LOCAL_PATH)/build/include
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE     := AN
LOCAL_SRC_FILES  := A.cpp B.cpp
LOCAL_SHARED_LIBRARIES := opencv-prebuilt
LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_LDLIBS     += -llog -ldl
include $(BUILD_SHARED_LIBRARY)

Application.mk

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-8

当我尝试编译时,为什么它一直给我错误no such directory or file found并指向#include <opencv2/opencv.hpp>目录中的jni语句?

我看过另一个类似的问题here,但我无法通过解决方案解决它

1 个答案:

答案 0 :(得分:2)

您应该只包含某些来源严格要求的标题文件,即

#include <DetectionBasedTracker.h>
#include <opencv2/core/core.hpp>
#include <opencv2/contrib/detection_based_tracker.hpp>

考虑到您所接受的答案作为参考作为参考的可能解决方案,您应该将放置SO文件的目录设置在 app / build.grade 上:

sourceSets.main {
    jniLibs.srcDir 'src/main/libs' //set .so files location to libs
    jni.srcDirs = [] //Disable automatic ndk-build call
}

tasks.withType(NdkCompile) {
    compileTask -> compileTask.enabled = false
}

尽管如此,我仍然会尝试在你的Android.mk中引用OpenCV.mk:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=off
OPENCV_LIB_TYPE:=STATIC
include /Users/egomez/dev/OpenCV4AndroidWorkspace/OpenCV-android-sdk/sdk/native/jni/OpenCV.mk

希望它有所帮助。