ndk-build returns non-zero 值 2(已经检查了所有其他堆栈问题!)

ndk-build returns non-zero value 2 (checked all the other stack questions already!)

我知道有几个标题相同的问题,但在我花了几个小时研究了每一个我能找到的问题之后,我决定 post 一个新问题。

我的Android.mk看起来像

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_SRC_FILES := com_lunaticcoding_colosseum_OpenCv.cpp

LOCAL_LDLIBS += -llog
LOCAL_MODULE := OpenCvFace


include $(BUILD_SHARED_LIBRARY)

我的Application.mk

APP_OPTIM := release
APP_PLATFORM := android-21
APP_STL := gnustl_static
APP_CPPFLAGS += -frtti
APP_CPPFLAGS += -fexceptions
APP_CPPFLAGS += -DANDROID
APP_ABI := armeabi-v7a

我的.h文件

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
#include "opencv2/opencv.hpp"
/* Header for class com_lunaticcoding_colosseum_OpenCv */

#ifndef _Included_com_lunaticcoding_colosseum_OpenCv
#define _Included_com_lunaticcoding_colosseum_OpenCv
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     com_lunaticcoding_colosseum_OpenCv
 * Method:    faceDetection
 * Signature: (J)V
 */
 void detect(Mat& frame);

 JNIEXPORT void JNICALL Java_com_lunaticcoding_colosseum_OpenCv_faceDetection
 (JNIEnv *, jclass, jlong);

#ifdef __cplusplus
}
#endif
#endif

我的 .cpp 文件

#include <jni.h>
#include "com_lunaticcoding_colosseum_OpenCv.h"

JNIEXPORT void JNICALL Java_com_lunaticcoding_colosseum_OpenCv_faceDetection
  (JNIEnv *, jclass, jlong addrRgba){
    //Mat& frame = *(Mat *) addrRgba;

    //detect(frame);
}

void detect(Mat& frame) {

}

我在属性文件中添加了 android.useDepricatedNdk=true,我的 "error message" 看起来像:

编辑(删除了错误消息,因为它已过时并使问题更难阅读)()我觉得我真的很接近 :O 但不知道我现在错过了什么

#include <jni.h>
#include <string>
#include <opencv>

extern "C" JNIEXPORT jstring

JNICALL
Java_com_lunaticcoding_opencvtest_MainActivity_getFace(
        JNIEnv *env,
        jobject /* this */) {
    std::string hello = "Hello from test";
    return env->NewStringUTF(hello.c_str());
}

跟随错误

构建命令失败。 使用参数 {--build /Users/lunaticcoding/AndroidStudioProjects/OpenCvTest2/app/.externalNativeBuild/cmake/debug/x86_64 --target OpenCvFace} 执行进程 /Users/lunaticcoding/Library/Android/sdk/cmake/3.6.4111459/bin/cmake 时出错 [1/2] CXX大楼object CMakeFiles/OpenCvFace.dir/src/main/cpp/OpenCvFace.cpp.o 失败:/Users/lunaticcoding/Library/Android/sdk/ndk-bundle/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ --target=x86_64-none-linux-android --gcc-toolchain=/Users/lunaticcoding/Library/Android/sdk/ndk-bundle/toolchains/x86_64-4.9/prebuilt/darwin-x86_64 --sysroot=/Users/lunaticcoding/Library/Android/sdk/ndk-bundle/sysroot -DOpenCvFace_EXPORTS -isystem /Users/lunaticcoding/Documents/OpenCV-android-sdk/sdk/native/jni/include -isystem /Users/lunaticcoding/Documents/OpenCV-android-sdk/sdk/native/jni/include/opencv -isystem /Users/lunaticcoding/Library/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /Users/lunaticcoding/Library/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/x86_64/include -isystem /Users/lunaticcoding/Library/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -isystem /Users/lunaticcoding/Library/Android/sdk/ndk-bundle/sysroot/usr/include/x86_64-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa,--noexecstack -Wformat -Werror=format-security -frtti -fexceptions -O0 -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/OpenCvFace.dir/src/main/cpp/OpenCvFace.cpp.o -MF CMakeFiles/OpenCvFace.dir/src/main/cpp/OpenCvFace.cpp.o.d -o CMakeFiles/OpenCvFace.dir/src/main/cpp/OpenCvFace.cpp.o -c /Users/lunaticcoding/AndroidStudioProjects/OpenCvTest2/app/src/main/cpp/OpenCvFace.cpp /Users/lunaticcoding/AndroidStudioProjects/OpenCvTest2/app/src/main/cpp/OpenCvFace.cpp:3:10: 致命错误: 'opencv' 找不到文件 包括 ^~~~~~~~ 产生 1 个错误。 忍者:构建停止:子命令失败。

确保您有 up-to-date Android Studio。删除 android.useDepricatedNdk=true 并按照官方 NDK 教程中的描述使用 externalNativeBuild。

我看到您需要 OpenCv 来构建和 运行 您的代码。请按照他们的说明在您的 Android.mk.

中正确引用所有需要的 headers 和库

请记住,Android Studio 会忽略 Application.mk 中定义的 APP_ABI。相反,您应该在 build.gradle.

中定义 abiFilters