在尝试构建我的android ndk项目时遇到以下错误。 Android Studio版本3.1.3
失败:构建失败,并出现异常。
出了什么问题: 任务':app:ndkBuild'的执行失败。
处理'命令'/ Users / bnaskar / Library / Android / sdk / ndk-bundle / ndk-build''的退出值非零2
尝试: 使用--info或--debug选项运行以获取更多日志输出。使用--scan运行以获取完整的见解。
例外是:
org.gradle.api.tasks.TaskExecutionException:任务':app:ndkBuild'的执行失败。 在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100) 在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70) 在org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)处 在org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62) 在org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54) 在org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60) 在org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97) 在org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87) 在org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)处 在org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52) 在org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54) 在org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43) 在org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34) 在org.gradle.execution.taskgraph.DefaultTaskGraphExecuter $ EventFiringTaskWorker $ 1.run(DefaultTaskGraphExecuter.java:248) 在org.gradle.internal.progress.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)处 在org.gradle.internal.progress.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328) 在org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199) 在org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110) 在org.gradle.execution.taskgraph.DefaultTaskGraphExecuter $ EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)处 在org.gradle.execution.taskgraph.DefaultTaskGraphExecuter $ EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)处 在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)处 在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker.access $ 200(DefaultTaskPlanExecutor.java:79) 在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker $ 1.execute(DefaultTaskPlanExecutor.java:104) 在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker $ 1.execute(DefaultTaskPlanExecutor.java:98) 在org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:626)处 在org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:581)处 在org.gradle.execution.taskgraph.DefaultTaskPlanExecutor $ TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98) 在org.gradle.internal.concurrent.ExecutorPolicy $ CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63) 在org.gradle.internal.concurrent.ManagedExecutorImpl $ 1.run(ManagedExecutorImpl.java:46) 在org.gradle.internal.concurrent.ThreadFactoryImpl $ ManagedThreadRunnable.run(ThreadFactoryImpl.java:55) 由以下原因引起:org.gradle.process.internal.ExecException:进程'command'/ Users / bnaskar / Library / Android / sdk / ndk-bundle / ndk-build''完成,返回值非零 在org.gradle.process.internal.DefaultExecHandle $ ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:382) 在org.gradle.process.internal.DefaultExecAction.execute(DefaultExecAction.java:31) 在org.gradle.api.tasks.AbstractExecTask.exec(AbstractExecTask.java:54) 在org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73) 在org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:46) 在org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39) 在org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26) 在org.gradle.api.internal.AbstractTask $ TaskActionWrapper.execute(AbstractTask.java:780) 在org.gradle.api.internal.AbstractTask $ TaskActionWrapper.execute(AbstractTask.java:747) 在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter $ 1.run(ExecuteActionsTaskExecuter.java:121) 在org.gradle.internal.progress.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)处 在org.gradle.internal.progress.DefaultBuildOperationExecutor $ RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328) 在org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199) 在org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110) 在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:110)处 在org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92) ...还有29个
7秒内失败 15个可执行的任务:1个已执行,14个最新 jampp-MacBook-Pro:BreakOut kllu $ ./gradlew installDebug --stacktrace
我的build.gradle结局
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.example.bnn.breakout"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
//testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets.main {
jni.srcDirs = [] //disable automatic ndk-build call
//jniLibs.srcDir "src/main/libs"
}
task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
commandLine "/Users/bnnk/Library/Android/sdk/ndk-bundle/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
}
buildTypes {
debug {
debuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:24.2.1'
implementation 'com.android.support:multidex:1.0.3'
testImplementation 'junit:junit:4.12'
}
答案 0 :(得分:2)
恐怕您不赞成使用为项目构建本机库的方法。新的Android插件(第3.1.2版)使用externalNativeBuild
。参见official instructions for upgrading。
简而言之,您需要类似
android {
externalNativeBuild {
ndkBuild {
path "Android.mk"
}
}
}
在模块 build.gradle 中。
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.example.bnn.breakout"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
//testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
externalNativeBuild {
ndkBuild {
path 'src/main/jni/Android.mk'
}
}
buildTypes {
debug {
debuggable true
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:24.2.1'
implementation 'com.android.support:multidex:1.0.3'
testImplementation 'junit:junit:4.12'
}
确保您的Android插件是最新的,请参见https://stackoverflow.com/a/50953301/192373