This part in the build.gradle
file seems to be causing failures to execute the application.
build.gradle文件中的这一部分似乎导致执行应用程序失败。
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.
ndkBuild任务是我在build.gradle文件中定义的任务。这是代码块。
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.
我仔细检查了ndk存储库的目录是否正确,并且它似乎不是失败的原因。
Here's the entire build.gradle
file's source code.
这是整个build.gradle文件的源代码。
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'
}
1 个解决方案
#1
0
I solved this issue by adding the Android SDK and NDK path to the .bash_profile
file as follows.
我通过将Android SDK和NDK路径添加到.bash_profile文件来解决了这个问题,如下所示。
export ANDROID_HOME=/usr/local/opt/android-sdk export PATH=${PATH}:/usr/local/opt/android-ndk
export ANDROID_HOME = / usr / local / opt / android-sdk export PATH = $ {PATH}:/ usr / local / opt / android-ndk
#1
0
I solved this issue by adding the Android SDK and NDK path to the .bash_profile
file as follows.
我通过将Android SDK和NDK路径添加到.bash_profile文件来解决了这个问题,如下所示。
export ANDROID_HOME=/usr/local/opt/android-sdk export PATH=${PATH}:/usr/local/opt/android-ndk
export ANDROID_HOME = / usr / local / opt / android-sdk export PATH = $ {PATH}:/ usr / local / opt / android-ndk