Android 错误:任务';的执行失败:应用程序:ndkBuild';
我正在使用NDK和OpenCV开发人体检测应用程序 得到这样的错误。 **错误:任务“:app:ndkBuild”的执行失败 启动进程“command”/home/android/android/Sdk/ndk bundle/ndk build.cmd”时出现问题** 计算机操作系统:Ubuntu 12.04(64位) Android studio版本为:3.0.1 你能帮我一下吗。在过去的两天里,我一直在努力解决这个错误。我在谷歌上搜索过,但解决方案并没有解决这个错误 我试过这样做: MainActivity.java build.gradle: 应用插件:“com.android.application”Android 错误:任务';的执行失败:应用程序:ndkBuild';,android,android-studio,opencv,android-ndk,build.gradle,Android,Android Studio,Opencv,Android Ndk,Build.gradle,我正在使用NDK和OpenCV开发人体检测应用程序 得到这样的错误。 **错误:任务“:app:ndkBuild”的执行失败 启动进程“command”/home/android/android/Sdk/ndk bundle/ndk build.cmd”时出现问题** 计算机操作系统:Ubuntu 12.04(64位) Android studio版本为:3.0.1 你能帮我一下吗。在过去的两天里,我一直在努力解决这个错误。我在谷歌上搜索过,但解决方案并没有解决这个错误 我试过这样做: Main
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.test.opencv"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets.main {
jni.srcDirs = [] //disable automatic ndk-build call
}
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
commandLine '/home/android/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
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets { main { jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/'] } }
buildTypes{
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation project(':openCVLibrary249')
}
Application.mk
#包括
JNIEXPORT void JNICALL Java\u com\u test\u opencv\u NativeClass\u humenDetection
(JNIEnv*env,jclass,obj){
return env->NewStringUTF(“这是来自JNI的”);
}
com_test_opencv_NativeClass.h
/*不要编辑此文件-它是机器生成的*/
#包括
/*类com\u test\u opencv\u NativeClass的标头*/
#ifndef包括com测试opencv NativeClass
#定义\u包含\u com\u测试\u opencv\u NativeClass
#ifdef_uucplusplus
外部“C”{
#恩迪夫
JNIEXPORT void JNICALL Java\u com\u test\u opencv\u NativeClass\u faceDetection
(JNIEnv*,jclass,jlong);
JNIEXPORT void JNICALL Java\u com\u test\u opencv\u NativeClass\u humenDetection
(JNIEnv*,jclass,jlong);
#ifdef_uucplusplus
}
#恩迪夫
#恩迪夫
您的构建。gradle使用了一个旧模板,与Android Studio 3不相关,而且,您可能合并了两个源代码,这两个源代码相互矛盾
然而,眼前的问题是,您的ndkBuild是为Windows构建的,如果您只是删除.cmd
,您的脚本可能在Ubuntu上工作。但让我们把它清理一下:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.test.opencv"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk {
abiFilters 'armeabi-v7a'
}
}
externalNativeBuild {
ndkBuild {
path "src/main/jni/Android.mk"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation project(':openCVLibrary249')
}
}
这假设
:openCVLibrary249
配置正确。您的构建。gradle使用旧模板,与Android Studio 3不相关,而且您可能合并了两个相互矛盾的源
然而,眼前的问题是,您的ndkBuild是为Windows构建的,如果您只是删除.cmd
,您的脚本可能在Ubuntu上工作。但让我们把它清理一下:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.test.opencv"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk {
abiFilters 'armeabi-v7a'
}
}
externalNativeBuild {
ndkBuild {
path "src/main/jni/Android.mk"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation project(':openCVLibrary249')
}
}
这假设
:openCVLibrary249
配置正确。感谢您的回复。更改build.prob后获取此错误:未知类型名称“obj”错误:(5,1)错误:无效函数“Java\u com\u test\u opencv\u NativeClass\u humenDetection”不应返回值[-Wreturn type]错误:(4,22)错误:未知类型名称“obj”错误:(5,1)错误:无效函数“Java\u com\u test\u opencv\u NativeClass\u humenDetection”不应返回值[-Wreturn type]是,文件com\u test\u opencv\u NativeClass.cpp
已损坏。将jclass,obj
更改为jcalss,jlong
。感谢您的帮助。我是NDK新手,打开简历。我正在向您学习NDK。我再次遇到另一个错误是..在添加.mk文件之前,它的工作状态将成功。现在它的工作状态将失败…我在question.java.lang.RuntimeException中添加了MainActivity.java:无法恢复活动{com.test.opencv/com.test.opencv.MainActivity}:java.lang.IllegalArgumentException:Service Intent必须是显式的:Intent{act=org.opencv.engine.BIND}原因:java.lang.IllegalArgumentException:Service Intent必须是显式的:Intent{act=org.opencv.engine.BIND}在com.test.opencv.MainActivity.onResume(MainActivity.java:76)上,感谢您的回复。更改build.prob后,收到此错误:未知类型名称“obj”错误:(5,1)错误:无效函数“java\u com\u test\u opencv\u NativeClass\u humenDetection”不应返回值[-Wreturn type]错误:(4,22)错误:未知类型名称“obj”错误:(5,1)错误:无效函数“Java_com_test_opencv_NativeClass_humenDetection”不应返回值[-Wreturn type]是的,文件com\u test\u opencv\u NativeClass.cpp
已损坏。将jclass,obj
更改为jcalss,jlong
。感谢您的帮助。我是NDK新手,打开CV。我正在从您的tube视频学习NDK。我再次遇到另一个错误是..在添加.mk文件之前,它的工作条件将成功。现在它将失败。。.I在question.java.lang.RuntimeException中添加了MainActivity.java:无法恢复活动{com.test.opencv/com.test.opencv.MainActivity}:java.lang.IllegalArgumentException:服务意图必须是显式的:意图{act=org.opencv.engine.BIND}原因:java.lang.IllegalArgumentException:Service Intent必须是显式的:Intent{act=org.opencv.engine.BIND}位于com.test.opencv.MainActivity.onResume(MainActivity.java:76)
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := com_test_opencv_NativeClass.cpp
LOCAL_LDLIBS += -llog
LOCAL_MODULE := MyLibs
include $(BUILD_SHARED_LIBRARY)
APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-16
com_test_opencv_NativeClass.cpp:
#include <com_test_opencv_NativeClass.h>
JNIEXPORT void JNICALL Java_com_test_opencv_NativeClass_humenDetection
(JNIEnv *env, jclass,obj){
return env->NewStringUTF("This is from JNI");
}
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_test_opencv_NativeClass */
#ifndef _Included_com_test_opencv_NativeClass
#define _Included_com_test_opencv_NativeClass
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT void JNICALL Java_com_test_opencv_NativeClass_faceDetection
(JNIEnv *, jclass, jlong);
JNIEXPORT void JNICALL Java_com_test_opencv_NativeClass_humenDetection
(JNIEnv *, jclass, jlong);
#ifdef __cplusplus
}
#endif
#endif
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.test.opencv"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
ndk {
abiFilters 'armeabi-v7a'
}
}
externalNativeBuild {
ndkBuild {
path "src/main/jni/Android.mk"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation project(':openCVLibrary249')
}
}