错误:ErorAndroid / sdk / ndk-bundle / ndk-build.cmd''以非零退出值2结束

时间:2017-03-23 18:25:19

标签: opencv android-ndk

我在我的项目中使用android Ndk,每当我想构建我的项目时它都会显示此错误

  

错误:任务':app:ndkBuild'的执行失败。处理'命令   'E:/Android/sdk/ndk-bundle/ndk-build.cmd''以非零退出结束   价值2

我创建了android.mk和application.mk

Application.mk

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-16

android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
C:\OpenCV-2.4.9-android-sdk
#opencv
OPENCVROOT:= C:\OpenCV-2.4.9-android-sdk
OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
OPENCV_LLB_TYPE:=SHARED
include ${OPENCVROOT}/sdk/native/jni/OpenCV.mk


LOCAL_SRC_FILES :=com_example_abr_ndkopencvtest2_OpencvNativeClass.cpp

LOCAL_LDLIBS += -llog
LOCAL_MODULE := MyOpencvLibs

include $(BUILD_SHARED_LIBRARY)

build.gradle文件

  apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.abr.ndkopencvtest2"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    sourceSets.main{
        jni.srcDirs = []
    }
    task ndkBuild(type: Exec,description: 'Compile JNI source via NDK'){
        commandLine "E:/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'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    compile project(':openCVLibrary249')
}

2 个答案:

答案 0 :(得分:0)

检查您是否添加了gradle - 本地属性

android.useDeprecatedNdk = true 

然后,在构建项目之后,您获得了 BUILD SUCCESSFUL 消息。 对于详细的流程,请确保您已正确按照步骤成功设置Android NDK构建环境。

答案 1 :(得分:-1)

我已经解决了我的问题我没有与android.mk或android.application有任何问题,这是我的错我用我的cpp文件和.h文件做了一些错误所以现在它正常工作