Issue
This part in the build.gradle
file seems to be causing failures to execute the application.
The error message on the console:
Error:Execution failed for task ':app:ndkBuild'.
> Process 'command '/Users/marshall/android-sdks/ndk-bundle/ndk-build'' finished with non-zero exit value 2
the ndkBuild task is the one I defined in the build.gradle
file. Here's the code block.
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
def ndkDir = project.plugins.findPlugin('com.android.application').sdkHandler.getNdkFolder()
commandLine "$ndkDir/ndk-build",
'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
}
I double-checked if the directory of the ndk repository is correct, and it doesn't seem to be the reason for the failure.
Here's the entire build.gradle
file's source code.
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.my.project"
minSdkVersion 21
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
android {
sourceSets {
main {
jni.srcDirs = []
}
}
}
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
def ndkDir = project.plugins.findPlugin('com.android.application').sdkHandler.getNdkFolder()
commandLine "$ndkDir/ndk-build",
'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
}
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'
})
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:25.0.0'
compile 'com.android.support:cardview-v7:25.0.0'
compile project(':openCVLibrary310')
compile 'com.android.support:appcompat-v7:25.0.0'
}
Solution
I solved this issue by adding the Android SDK and NDK path to the .bash_profile
file as follows.
export ANDROID_HOME=/usr/local/opt/android-sdk
export PATH=${PATH}:/usr/local/opt/android-ndk
Answered By - marshallslee
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.