如何修复Android Studio中Gradle同步失败的CreateProcess错误=2?(Windows)

wrrgggsh  于 2023-05-15  发布在  Android
关注(0)|答案(1)|浏览(194)

我遇到了这个问题,在网上搜索,我现在还没有找到解决方案。我已经尝试使用不同的JDK位置,但问题仍然存在。我该怎么解决?

日志

29 15:07:07,327 [e-1024-b 02] INFO - idea.project.IndexingSuspender -正在启动项目的批处理更新:项目C:\Users\lab\Desktop\appandroid\heartbeat-android-master
2018-08-29 15:07:08,173 [e-1024-b02] INFO - idea.project.IndexingSuspender - Consuming IndexingSuspender deactivation event:构建_完成
2018-08-29 15:07:08,173 [e-1024-b 02] INFO - idea.project.IndexingSuspender -正在完成项目的批量更新:项目C:\Users\lab\Desktop\appandroid\heartbeat-android-master
2018-08-29 15:07:08,174 [e-1024-b 02] INFO - ild.invoker.GradleBuildInvoker - Gradle构建在890 ms内完成
2018-08-29 15:07:08,179 [e-1024-b 02] INFO - pl.ProjectRootManagerComponent -项目根已更改
2018-08-29 15:07:08,204 [e-1024-b 02] INFO - pl.ProjectRootManagerComponent -项目根已更改
2018-08-29 15:07:08,239 [thread 150] INFO - .diagnostic.PerformanceWatcher - Pushing properties took 1ms;一般React性:ok; EDT响应性:ok
2018-08-29 15:07:08,253 [thread 150] INFO - .diagnostic.PerformanceWatcher - Indexable file iteration took 14ms;一般React性:ok; EDT响应性:ok
2018-08-29 15:07:14,837 [e-1024-b02] INFO - ide.actions.ShowFilePathAction -
退出代码1

事件日志

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:ndkBuild'.
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
    at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
    at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
    at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60)
    at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:97)
    at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:87)
    at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
    at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
    at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:248)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
    at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:241)
    at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:230)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:626)
    at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:581)
    at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.gradle.process.internal.ExecException: A problem occurred starting process 'command 'C:\Users\danilo\AppData\Local\Android\Sdk\ndk-bundle/ndk-build''
    at org.gradle.process.internal.DefaultExecHandle.execExceptionFor(DefaultExecHandle.java:222)
    at org.gradle.process.internal.DefaultExecHandle.setEndStateInfo(DefaultExecHandle.java:202)
    at org.gradle.process.internal.DefaultExecHandle.failed(DefaultExecHandle.java:342)
    at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:86)
    at org.gradle.internal.operations.BuildOperationIdentifierPreservingRunnable.run(BuildOperationIdentifierPreservingRunnable.java:39)
    ... 6 more
Caused by: net.rubygrapefruit.platform.NativeException: Could not start 'C:\Users\danilo\AppData\Local\Android\Sdk\ndk-bundle/ndk-build'
    at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:27)
    at net.rubygrapefruit.platform.internal.WindowsProcessLauncher.start(WindowsProcessLauncher.java:22)
    at net.rubygrapefruit.platform.internal.WrapperProcessLauncher.start(WrapperProcessLauncher.java:36)
    at org.gradle.process.internal.ExecHandleRunner.run(ExecHandleRunner.java:68)
    ... 7 more
Caused by: java.io.IOException: Cannot run program "C:\Users\danilo\AppData\Local\Android\Sdk\ndk-bundle/ndk-build" (in directory "C:\Users\danilo\Desktop\appandroid\heartbeat-android-master\app"): CreateProcess error=2, Impossibile trovare il file specificato
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at net.rubygrapefruit.platform.internal.DefaultProcessLauncher.start(DefaultProcessLauncher.java:25)
    ... 10 more
Caused by: java.io.IOException: CreateProcess error=2, Impossibile trovare il file specificato
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(ProcessImpl.java:386)
    at java.lang.ProcessImpl.start(ProcessImpl.java:137)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
    ... 11 more

文件 build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '27.0.3'

    defaultConfig {
        applicationId "com.prouast.heartbeat"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

    }

    // add a task that calls regular ndk-build(.cmd) script from app directory
    task ndkBuild(type: Exec, description: 'Compile JNI source via NDK') {
        def ndkDir = android.ndkDirectory
        commandLine "$ndkDir/ndk-build",
                '-C', file('src/main/jni').absolutePath, // relative path to jni source
                'NDK_LIBS_OUT=../jniLibs',
                '-j', Runtime.runtime.availableProcessors(),
                'all',
                'NDK_DEBUG=1'
    }

    task ndkClean(type: Exec, description: 'Clean JNI object files') {
        def ndkDir = android.ndkDirectory
        commandLine "$ndkDir/ndk-build",
                '-C', file('src/main/jni').absolutePath, // relative path to jni source
                'NDK_LIBS_OUT=../jniLibs',
                'clean'
    }

    // add this task as a dependency of Java compilation
    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn(['ndkBuild'])
    }

    clean.dependsOn(['ndkClean'])

    sourceSets.main {
        jni.srcDirs = []
        //jniLibs.srcDir 'src/main/libs'
    }

    buildTypes {
        debug {
            debuggable true
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation 'org.apache.commons:commons-io:1.3.2'
    implementation 'com.android.support:appcompat-v7:23.1.1'
    implementation project(':libraries:opencv')

根据@Alex Cohn的建议,我已经解决了一些问题,但我遇到了其他错误,遵循日志错误文件(出了什么问题?):

Build command failed.

Error while executing process C:\Users\danilo\AppData\Local\Android\Sdk\ndk-bundle\ndk-build.cmd with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users\danilo\Desktop\appandroid\heartbeat-android-master\app\src\main\jni\Android.mk NDK_APPLICATION_MK=C:\Users\danilo\Desktop\appandroid\heartbeat-android-master\app\src\main\jni\Application.mk APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=1 APP_PLATFORM=android-15 NDK_OUT=C:/Users/danilo/Desktop/appandroid/heartbeat-android-master/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=C:\Users\danilo\Desktop\appandroid\heartbeat-android-master\app\build\intermediates\ndkBuild\debug\lib APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n}

Android NDK: WARNING: APP_STL gnustl_shared is deprecated and will be removed in the next release. Please switch to either c++_static or c++_shared. See https://developer.android.com/ndk/guides/cpp-support.html for more information.

process_begin: CreateProcess(NULL, "", ...) failed.

../../../../sources/ffmpeg-2.2.3/android/arm/Android.mk: No such file or directory
Open File

Android NDK: Module FFmpegEncoder depends on undefined modules: avformat-55 avcodec-55 avutil-52 swscale-2
Open File

*** Android NDK: Aborting (set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies)    .  Stop.
Open File

Build command failed.

Error while executing process C:\Users\danilo\AppData\Local\Android\Sdk\ndk-bundle\ndk-build.cmd with arguments {NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\Users\danilo\Desktop\appandroid\heartbeat-android-master\app\src\main\jni\Android.mk NDK_APPLICATION_MK=C:\Users\danilo\Desktop\appandroid\heartbeat-android-master\app\src\main\jni\Application.mk APP_ABI=armeabi-v7a NDK_ALL_ABIS=armeabi-v7a NDK_DEBUG=0 APP_PLATFORM=android-15 NDK_OUT=C:/Users/danilo/Desktop/appandroid/heartbeat-android-master/app/build/intermediates/ndkBuild/release/obj NDK_LIBS_OUT=C:\Users\danilo\Desktop\appandroid\heartbeat-android-master\app\build\intermediates\ndkBuild\release\lib APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n}

Android NDK: WARNING: APP_STL gnustl_shared is deprecated and will be removed in the next release. Please switch to either c++_static or c++_shared. See https://developer.android.com/ndk/guides/cpp-support.html for more information.

process_begin: CreateProcess(NULL, "", ...) failed.

../../../../sources/ffmpeg-2.2.3/android/arm/Android.mk: No such file or directory
Open File

Android NDK: Module FFmpegEncoder depends on undefined modules: avformat-55 avcodec-55 avutil-52 swscale-2
Open File

*** Android NDK: Aborting (set APP_ALLOW_MISSING_DEPS=true to allow missing dependencies)    .  Stop.
Open File
wvyml7n5

wvyml7n51#

您的Gradle脚本已针对Linux而非Windows进行了优化。在Windows上,您需要"$ndkDir/ndk-build.cmd"而不是"$ndkDir/ndk-build"
如果您使用Android Studio 3.2或更高版本,请重写Gradle脚本以使用新的NDK集成。参见official walkthrough
以下是build.gradle的外观:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '27.0.3'

    defaultConfig {
        applicationId "com.prouast.heartbeat"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }

    buildTypes {
        debug {
            debuggable true
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation 'org.apache.commons:commons-io:1.3.2'
    implementation 'com.android.support:appcompat-v7:23.1.1'
    implementation project(':libraries:opencv')
}

android {
    externalNativeBuild {
        ndkBuild {
            path 'src/main/jni/Android.mk'
        }
    }
    defaultConfig {
        ndk {
            abiFilters 'armeabi-v7a'
        }
    }
}

不幸的是,我不能保证您的src/main/jni/Android.mk在您的Windows机器上正常工作。此外,请确保您使用NDK和Gradle插件的兼容版本。

相关问题