0

I am using latest version of ndk (18.1). Whenever I try to compile my code it shows me Execution failed for task ':app:ndkBuild'

I tried 2 different versions of ndk (18.1) and (14.1), Both shows almost same error while the only difference is that;

  • ndk (18.1) shows Exit Value 2
  • ndk (14.1) shows Exit Value -1

jni Path:

".mk" ".h" ".cpp" file location

Build.Gradle:

apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
    applicationId "com.fyp.major.fyp1"
    minSdkVersion 21
    targetSdkVersion 28
    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 "C:/Users/MaJoR/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
}

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:28.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':openCVLibrary344')
}

ANDROID.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

#opencv
OPENCVROOT:= C:\OpenCV-3.4.0-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_fyp_major_fyp1_OpencvClass.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

OUTPUT Error while using ndk 18.1

non-zero exit value 2

OUTPUT Error while using ndk 14.1

non-zero exit value -1

Any Solution for these Errors?

shizhen
  • 12,251
  • 9
  • 52
  • 88
Fahad ALï
  • 33
  • 6
  • 1
    It's probably time to switch from custom 'ndkBuild' task to [**externalNativeBuild**](https://developer.android.com/studio/projects/add-native-code#ndkCompile) method. You can keep your **Android.mk** and enjoy full IDE integration. – Alex Cohn Dec 17 '18 at 07:25

1 Answers1

1

NDK r18 has dropped gnustl, so you must rebuild OpenCV for libc++.

As for NDK r14.1, there is too little info to explain the failure. Note that the screenshot mentions that ndk-stack.cmd and not ndk-build.cmd was run there. Could it be a typo when you switched to the older NDK?

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • In **NDK r14.1** the exit value -1 was because I was running ndk-stack.cmd instead of ndk-build.cmd (as you mention above). Now my code is running without any error. @Alex Thankyou ...... But I have still issue if I use NDK 18.1. Please check these images (https://imgur.com/a/sW6K1pJ) After installation I donot do any other setting for Cmake. Just run the code on terminal. Now how to create Cmakelists.text? – Fahad ALï Dec 17 '18 at 21:37
  • I don't recommend rebuilding OpenCV, it's much safer to use NDK r14 until they have official support for r18. – Alex Cohn Dec 18 '18 at 17:46