我使用NDK和OpenCV开发人体检测应用程序。
得到这样的错误。 **错误:任务':app:ndkBuild'。
的执行失败启动流程问题' /home/android/Android/Sdk/ndk-bundle/ndk-build.cmd'' **
计算机操作系统:Ubuntu 12.04(64位)。
Android工作室版本是:3.0.1
你能不能请帮助我。最近2天的话 - 我试图解决这个错误。我在谷歌搜索过,但是这个解决方案没有解决这个错误。
我试过这样的话:
MainActivity.java
public class MainActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2 {
public static final String TAG = "MainActivity";
JavaCameraView javaCameraView;
Mat mRgba,igray,iCanny;
BaseLoaderCallback mLoaderCallaBack = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case BaseLoaderCallback.SUCCESS: {
javaCameraView.enableView();
break;
}
default: {
super.onManagerConnected(status);
break;
}
}
super.onManagerConnected(status);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
javaCameraView =(JavaCameraView)findViewById(R.id.java_camera_view);
javaCameraView.setVisibility(SurfaceView.VISIBLE);
javaCameraView.setCvCameraViewListener(this);
}
@Override
protected void onPause(){
super.onPause();
if(javaCameraView!=null)
javaCameraView.disableView();
}
protected void onDistroy(){
super.onPause();
if(javaCameraView!=null)
javaCameraView.disableView();
}
protected void onResume(){
super.onResume();
if(OpenCVLoader.initDebug()){
Log.d(TAG,"SUCESSES");
mLoaderCallaBack.onManagerConnected(LoaderCallbackInterface.SUCCESS);
}else {
Log.d(TAG,"FAIL");
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_9,this,mLoaderCallaBack);
}
}
@Override
public void onCameraViewStarted(int width, int height) {
mRgba = new Mat(height,width, CvType.CV_8UC4);
igray = new Mat(height,width, CvType.CV_8UC4);
}
@Override
public void onCameraViewStopped() {
mRgba.release();
}
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
//NativeClass.faceDetection(mRgba.getNotificationObjAdde());
//Imgproc.ctv
return mRgba;
}
}
的build.gradle:
申请插件:' 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"
}
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')
}
Android.mk
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)
Application.mk
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");
}
com_test_opencv_NativeClass.h
/* 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
答案 0 :(得分:3)
您的 build.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
配置正确。