Gradle 3.0 BuildException无法创建目录

时间:2017-10-19 12:02:12

标签: android windows android-studio gradle

我在Windows上并更新到Android Studio(AS)3.0 RC1。当我尝试使用gradle通过AS或终端构建我们的项目时它会停止,Stacktrace就在最后。奇怪的是,在我的同事Mac上它只是建立。

所以我猜测路径有问题。我找不到任何关于此BuildException的具体内容。任何人都知道为什么路径看起来重复? C:\Development\Workspace\Project\app\build\outputs\apk\Test\debug\C:\Development\Workspace\Project\app\build\outputs\apk\Test\debug

我还能尝试解决这个问题吗?我清理,重建并重新开始我所能做的一切。

更新我刚刚将AS更新为3.0 RC 2并仍然遇到同样的问题。

更新稳定的AS 3.0版本也是如此:(

>FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:packageTestDebug'.
> Cannot create directory C:\Development\Workspace\Project\app\build\outputs\apk\Test\debug\C:\Development\Workspace\Project\app\build\outputs\apk\Test\debug

* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:packageTestDebug'.
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.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:63)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
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:197)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
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:124)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:80)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:105)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:99)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:625)
at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:580)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:99)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
Caused by: org.gradle.tooling.BuildException: Cannot create directory C:\Development\Workspace\Project\app\build\outputs\apk\Test\debug\C:\Development\Workspace\Project\app\build\outputs\apk\Test\debug
at com.android.build.gradle.internal.scope.OutputScope.lambda$parallelForEachOutput$10(OutputScope.java:241)
at com.android.build.gradle.internal.scope.OutputScope.parallelForEachOutput(OutputScope.java:236)
at com.android.build.gradle.internal.scope.OutputScope.parallelForEachOutput(OutputScope.java:197)
at com.android.build.gradle.internal.scope.OutputScope.parallelForEachOutput(OutputScope.java:181)
at com.android.build.gradle.tasks.PackageAndroidArtifact.doFullTaskAction(PackageAndroidArtifact.java:471)
at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:109)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:173)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:121)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:122)
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:197)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:107)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:111)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:92)
... 27 more
Caused by: java.lang.RuntimeException: Cannot create directory C:\Development\Workspace\Project\app\build\outputs\apk\Test\debug\C:\Development\Workspace\Project\app\build\outputs\apk\Test\debug
at com.android.utils.FileUtils.mkdirs(FileUtils.java:215)
at com.android.build.gradle.tasks.PackageAndroidArtifact.doTask(PackageAndroidArtifact.java:664)
at com.android.build.gradle.tasks.PackageAndroidArtifact.splitFullAction(PackageAndroidArtifact.java:522)
at com.android.build.gradle.internal.scope.OutputScope.lambda$parallelForEachOutput$6(OutputScope.java:186)
at com.android.build.gradle.internal.scope.OutputScope.lambda$parallelForEachOutput$7(OutputScope.java:203)
at com.android.build.gradle.internal.scope.OutputScope.lambda$null$8(OutputScope.java:225)

4 个答案:

答案 0 :(得分:34)

随着Android Studio 3.0的稳定发布,我深入挖掘了一下。原来我们的脚本命名APK没有工作,但只在Windows上打破。

旧脚本:

applicationVariants.all { variant ->
    variant.outputs.each { output ->
        def outputFile = output.outputFile
        if (outputFile != null && outputFile.name.endsWith('.apk')) {
            def fileName = outputFile.name.replace('.apk', "-${versionName}.apk")
            output.outputFile = new File(outputFile.parent, fileName)
        }
    }
}

修正脚本:

applicationVariants.all { variant ->
    variant.outputs.all {
        outputFileName = "${variant.name}-${variant.versionName}.apk"
    }
}

答案 1 :(得分:1)

在您的gradle文件(模块级别)中,您使用applicationVariants重命名您的apk或类似的东西吗? 我不得不在gradle文件中删除这部分来解决这个问题。

答案 2 :(得分:0)

我在Linux或Windows上使用Android Studio 3.0构建相同的应用程序。 升级到Gradle 3.0.1之后,我在Windows上遇到了类似的问题,而它在Linux上运行良好:

  

错误:任务':smsreminder:packageDebug'执行失败。   >无法创建目录C:\ Users \ Florent \ AndroidStudioProjects \ MyApp \ myapp \ build \ outputs \ apk \ debug \ C:\ Users \ Florent \ AndroidStudioProjects \ MyApp \ myapp \ build \ outputs \ apk \ debug

感谢Leo的上述回答,我让这个更友好的apk名称:

outputFileName = "${variant.name}-${variant.versionName}.apk"
=> produces: debug-x.y.apk

outputFileName = output.outputFile.name + ".${variant.versionName}.apk"
=> produces: MyAppName.x.y.apk

否则,如果想要保持默认值,我发现这也有效:

if (org.gradle.internal.os.OperatingSystem.current().windows)
            outputFileName = "${variant.name}-${variant.versionName}.apk"
        else
            outputFileName = new File(output.outputFile.parent, outputFileName.replace(output.outputFile.name, defaultConfig.applicationId + ".apk"))

答案 3 :(得分:0)

android.applicationVariants.all { variant ->
  variant.outputs.all {
      outputFileName = "${variant.name}-${variant.versionName}.apk"

此代码将解决问题。!!此脚本中的上述答案稍有变化