未找到Android Studio“opencv2 / core / core.hpp”文件

时间:2017-03-19 18:42:43

标签: android c++ android-studio opencv

我正在使用Android Studio 2.3并导致致命错误:找不到'opencv2 / core / core.hpp'文件

我看到许多类似的问题没有构建Android.mk,但我的Android.mk应该已经构建。

如果更改包含Android.mk中OpenCV.mk的路径,它将报告文件未找到错误,因此我认为Android.mk已包含在构建过​​程中且文件路径正确。

如果包含路径正确,OpenCV.mk应该找到文件夹opencv2但我仍然找不到文件错误。

有没有其他方法可以在Android Studio中设置包含路径?

我的构建脚本出了什么问题?

本机lib.cpp

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

Android.mk

LOCAL_PATH := $(call my-dir)

OPENCV_CAMERA_MODULES:=off
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=SHARED
include $(LOCAL_PATH)/../../../../../../../../OpenCV-android-sdk/sdk/native/jni/OpenCV.mk

LOCAL_C_INCLUDES+=$(LOCAL_PATH)/../../../../../../../../OpenCV-android-sdk/sdk/native/jni/include/
LOCAL_SRC_FILES := native-lib.cpp
LOCAL_LDLIBS +=  -llog -ldl
LOCAL_MODULE:= native-lib

include $(BUILD_SHARED_LIBRARY)

Application.mk

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi armeabi-v7a arm64-v8a

的build.gradle

android {
          ......
          ......

         sourceSets.main {
              jni.srcDirs = [] //disable automatic ndk-build call
         }

         task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
              commandLine 'F:\\Android_SDK\\ndk-bundle\\ndk-build.cmd',
              '-C', file('src\\main\\jni').absolutePath,
              'NDK_DEBUG=1',
              'V=1'
         }

         tasks.withType(JavaCompile) {
            compileTask -> compileTask.dependsOn ndkBuild
         }
}

文件结构如下

app/src/main/jni/Android.mk
app/src/main/jni/Application.mk
app/src/main/jni/native-lib.cpp
app/build.gradle

1 个答案:

答案 0 :(得分:0)

您是否将OpenCV Library导入为模块?您可以在 Android.mk 文件

中尝试这样做吗?
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

 #opencv

OPENCVROOT:= F:/Android/Libs/OpenCV
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=SHARED
include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk

LOCAL_SRC_FILES := native-lib.cpp
LOCAL_LDLIBS += -llog
LOCAL_MODULE := MyOpenCVLibs
include $(BUILD_SHARED_LIBRARY)

在命令行下的 build.gradle 中,您可以像这样添加

commandLine "F:\\Android\\NDK\\android-ndk-r14\\build\\ndk-build.cmd",
                'NDK_PROJECT_PATH=build/intermediates/ndk',
                'NDK_LIBS_OUT=src/main/jniLibs',
                'APP_BUILD_SCRIPT=src/main/jni/Android.mk',
                'NDK_APPLICATION_MK=src/main/jni/Application.mk'