[英]Android Studio with opencv for android ndk, opencv header files not found
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: 我正在开发用于Android OpenCV开发的Android Studio,但是当我编译eclipse中的项目时,我遇到了这个错误:
D:\\software\\AndroidStudioProjects\\CameraMe\\openCVSamplefacedetection\\src\\main\\jni\\DetectionBasedTracker_jni.cpp:2:33: fatal error: opencv2/core/core.hpp: No such file or directory D:\\ software \\ AndroidStudioProjects \\ CameraMe \\ openCVSamplefacedetection \\ src \\ main \\ jni \\ DetectionBasedTracker_jni.cpp:2:33:致命错误:opencv2 / core / core.hpp:没有这样的文件或目录
I guess the headers for opencv was not found, but I don't know what's wrong. 我想opencv的标题找不到,但我不知道出了什么问题。
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)
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-8
#include <DetectionBasedTracker_jni.h>
#include <opencv2/core/core.hpp>
#include <opencv2/contrib/detection_based_tracker.hpp>
......
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时,默认会忽略您的Makefile,并且即时生成新的Makefile,而不会正确引用OpenCV,因为它不受支持。
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. 这就是NDK构建目前在Android Studio中运行的方式,并且它已被弃用,而更好的方法是在工作中。
You can deactivate this built-in NDK support and get your Makefiles to be used instead, by doing this inside your build.gradle : 您可以通过在build.gradle中执行此操作来取消激活此内置NDK支持并改为使用Makefile:
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
}
}
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. 顺便说一句,我看你设置APP_ABI
只armeabi-V7A,但OpenCV的也能支持x86和MIPS,所以你也可以轻松地扩展您的支持,这些平台。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.