大家好我正在关注Youtube的教程,使用android studio创建一个移动应用程序,遗憾的是我遇到了一些错误而无法自己解决。 .cpp和.h文件的错误相同。任何帮助将不胜感激,提前感谢! :)
这是我的gradle构建中的错误:
Error:Execution failed for task ':app:ndkBuild'.
> Process 'command 'C:/Users/dell/AppData/Local/Android/sdk/ndk-bundle/ndk-
build.cmd'' finished with non-zero exit value 2
这是我的.h文件(Android工作室说“jint”存在拼写错误,但缺少“;”):
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
/* Header for class com_example_dell_mpdetecthumans_OpencvNativeClass */
#ifndef _Included_com_example_dell_humandetectionndk_OpencvNativeClass
#define _Included_com_example_dell_humandetectionndk_OpencvNativeClass
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_example_dell_mpdetecthumans_OpencvNativeClass
* Method: convertGray
* Signature: (JJ)I
*/
int toGray(Mat img, Mat& gray);
JNIEXPORT jint JNICALL
Java_com_example_dell_humandetectionndk_OpencvNativeClass_convertGray
(JNIEnv *, jclass, jlong, jlong);
#ifdef __cplusplus
}
#endif
#endif
.cpp文件(Android工作室说“jint”存在拼写错误,但缺少“;”):
#include <com_example_dell_humandetectionndk_OpencvNativeClass.h>
JNIEXPORT jint JNICALL
Java_com_example_dell_humandetectionndk_OpencvNativeClass_convertGray
(JNIEnv *, jclass, jlong addrRgba, jlong addrGray){
Mat& mRgb = *(Mat*)addrRgba;
Mat& mGray = *(Mat*)addrGray;
int conv;
jint retVal;
conv = toGray(mRgb, mGray);
retVal = (jint)conv;
return retVal;
}
int toGray(Mat img, Mat& gray){
cvtColor(img, gray, CV_RGBA2GRAY);
if(gray.rows==img.rows && gray.cols==img.cols)
return 1;
return 0;
}
Android.mk:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#opencv
OPENCVROOT:= C:\OpenCV-2.4.9-android-sdk
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=SHARED
include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk
LOCAL_SRC_FILES := com_example_dell_humandetectionndk_OpencvNativeClass.cpp
LOCAL_LDLIBS += -llog
LOCAL_MODULE := MyOpencvLibs
include $(BUILD_SHARED_LIBRARY)
我的application.mk
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-16
我的应用build.gradle
sourceSets.main {
jni.srcDirs = [] //disable automatic ndk-build call
}
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
commandLine "C:/Users/dell/AppData/Local/Android/sdk/ndk-bundle/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'
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
这是我关注的教程的链接:https://www.youtube.com/watch?v=Oq3oiCfSgbo&t=727s
答案 0 :(得分:0)
大部分错误消息可能直接位于您粘贴的内容之上。一般来说,工作室的构建输出如下:
我们需要实际构建系统的输出来诊断出什么 - 你可以在错误上面滚动:执行失败以执行任务&#39;:app:ndkBuild&#39;咬一下,看看是否有任何看起来像失败的东西?