带有opencv for android ndk的Android Studio,找不到opencv头文件 [英] Android Studio with opencv for android ndk, opencv header files not found
问题描述
我正在使用 Android Studio 进行 Android OpenCV 开发,但是当我编译在 Eclipse 中正常的项目时,出现此错误:
I'm getting to Android Studio for Android OpenCV developing, but when I compile the project which was ok in eclipse, I got this error:
D:\software\AndroidStudioProjects\CameraMe\openCVSamplefacedetection\src\main\jni\DetectionBasedTracker_jni.cpp:2:33:致命错误:opencv2/core/core.hpp:没有那个文件或目录
D:\software\AndroidStudioProjects\CameraMe\openCVSamplefacedetection\src\main\jni\DetectionBasedTracker_jni.cpp:2:33: fatal error: opencv2/core/core.hpp: No such file or directory
我猜没有找到 opencv 的头文件,但我不知道出了什么问题.
I guess the headers for opencv was not found, but I don't know what's wrong.
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#OPENCV_CAMERA_MODULES:=off
#OPENCV_INSTALL_MODULES:=off
#OPENCV_LIB_TYPE:=SHARED
include D:\eclipse\OpenCV_2.4.9_android_sdk\sdk\native\jni\OpenCV.mk
LOCAL_SRC_FILES := DetectionBasedTracker_jni.cpp
LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_LDLIBS += -llog -ldl
LOCAL_MODULE := detection_based_tracker
include $(BUILD_SHARED_LIBRARY)
应用程序.mk
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-8
DetectionBasedTracker_jni.cpp
#include <DetectionBasedTracker_jni.h>
#include <opencv2/core/core.hpp>
#include <opencv2/contrib/detection_based_tracker.hpp>
......
推荐答案
当您使用 Android Studio 时,默认情况下会忽略您的 Makefile 并即时生成新的 Makefile,未正确引用 OpenCV,因为它不受支持.
as you're using Android Studio, your Makefiles are ignored by default and new ones are generated on-the-fly, without properly referencing OpenCV as it's not supported.
这就是当前在 Android Studio 中运行 NDK 构建的方式,它已被弃用,但正在开发一种更好的方法.
This is how NDK builds are currently working from Android Studio and it's deprecated while a better way to do it is in the work.
通过在 build.gradle 中执行此操作,您可以停用此内置 NDK 支持并改为使用您的 Makefile:
You can deactivate this built-in NDK support and get your Makefiles to be used instead, by doing this inside your build.gradle:
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.application'
android {
...
sourceSets.main {
jniLibs.srcDir 'src/main/libs' //set .so files directory to libs
jni.srcDirs = [] //disable automatic ndk-build call
}
// call regular ndk-build(.cmd) script from app directory
task ndkBuild(type: Exec) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'ndk-build.cmd', '-C', file('src/main').absolutePath
} else {
commandLine 'ndk-build', '-C', file('src/main').absolutePath
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
}
顺便说一句,我看到你将 APP_ABI
设置为 armeabi-v7a,但 OpenCV 也支持 x86 和 mips>,因此您还可以轻松地将支持扩展到这些平台.
btw, I see you set APP_ABI
only to armeabi-v7a, but OpenCV also supports x86 and mips, so you can also easily extend your support to these platforms.
这篇关于带有opencv for android ndk的Android Studio,找不到opencv头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!