Gradle:文件名,目录名或卷标语法不正确

时间:2013-11-23 21:33:35

标签: android gradle android-studio

我已经安装并设置了最新版本的Android Studio(0.3.6,nov 14发行版),但在尝试构建我的项目(使用Android Studio新项目向导制作的一个简单的hello world项目)时,我得到了以下错误:

E:\Backups\etc\TestProj2>gradlew --stacktrace build
:Test2:preBuild UP-TO-DATE
:Test2:preDefaultFlavorDebugBuild UP-TO-DATE
:Test2:prepareDefaultFlavorDebugDependencies
:Test2:compileDefaultFlavorDebugAidl
:Test2:compileDefaultFlavorDebugRenderscript
:Test2:generateDefaultFlavorDebugBuildConfig
:Test2:mergeDefaultFlavorDebugAssets
:Test2:mergeDefaultFlavorDebugResources
:Test2:processDefaultFlavorDebugManifest
:Test2:processDefaultFlavorDebugResources
:Test2:generateDefaultFlavorDebugSources
:Test2:compileDefaultFlavorDebug
:Test2:dexDefaultFlavorDebug
The filename, directory name, or volume label syntax is incorrect.
:Test2:dexDefaultFlavorDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':Test2:dexDefaultFlavorDebug'.
> Could not call IncrementalTask.taskAction() on task ':Test2:dexDefaultFlavorDe
bug'

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

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':Test2:d
exDefaultFlavorDebug'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecuteActions(ExecuteActionsTaskExecuter.java:69)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecute(ExecuteActionsTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExec
uter.execute(PostExecutionAnalysisTaskExecuter.java:35)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.exec
ute(SkipUpToDateTaskExecuter.java:64)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execut
e(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecu
ter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter
.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execut
e(SkipOnlyIfTaskExecuter.java:53)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter
.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailur
e(AbstractTask.java:283)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorW
orker.executeTask(AbstractTaskPlanExecutor.java:79)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorW
orker.processTask(AbstractTaskPlanExecutor.java:63)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorW
orker.run(AbstractTaskPlanExecutor.java:51)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$1.run(DefaultT
askPlanExecutor.java:33)
        at org.gradle.internal.Factories$1.create(Factories.java:22)
        at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(Def
aultCacheAccess.java:214)
        at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(Def
aultCacheAccess.java:276)
        at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunning
Operation(DefaultPersistentDirectoryStore.java:142)
        at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStat
eCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:78)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(Defaul
tTaskPlanExecutor.java:31)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(Defau
ltTaskGraphExecuter.java:86)
        at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTask
ExecutionAction.java:29)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
r.java:61)
        at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExec
uter.java:23)
        at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecu
ter.java:67)
        at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildEx
ecutionAction.java:32)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
r.java:61)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
r.java:54)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(Default
GradleLauncher.java:166)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradle
Launcher.java:113)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLaun
cher.java:81)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildCon
troller.run(InProcessBuildActionExecuter.java:64)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.jav
a:33)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.jav
a:24)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProce
ssBuildActionExecuter.java:35)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProce
ssBuildActionExecuter.java:26)
        at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
        at org.gradle.api.internal.Actions$RunnableActionAdapter.execute(Actions
.java:171)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.
execute(CommandLineActionFactory.java:201)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.
execute(CommandLineActionFactory.java:174)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(
CommandLineActionFactory.java:170)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(
CommandLineActionFactory.java:139)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep
ortingAction.java:33)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep
ortingAction.java:22)
        at org.gradle.launcher.Main.doAction(Main.java:46)
        at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
        at org.gradle.launcher.Main.main(Main.java:37)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBoots
trap.java:50)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.j
ava:32)
        at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
        at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.ja
va:33)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:130)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
Caused by: org.gradle.api.GradleException: Could not call IncrementalTask.taskAc
tion() on task ':Test2:dexDefaultFlavorDebug'
        at org.gradle.util.JavaMethod.invoke(JavaMethod.java:69)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskF
actory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:219)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskF
actory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:212)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskF
actory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:201)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(Abstra
ctTask.java:527)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(Abstra
ctTask.java:510)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecuteAction(ExecuteActionsTaskExecuter.java:80)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecuteActions(ExecuteActionsTaskExecuter.java:61)
        ... 52 more
Caused by: com.android.ide.common.internal.LoggedErrorException: Failed to run c
ommand:
        C:\Android\android-studio2\sdk\build-tools\android-4.4\dx.bat --dex --ou
tput E:\Backups\etc\TestProj2\Test2\build\libs\Test2-defaultFlavor-debug.dex E:\
Backups\etc\TestProj2\Test2\build\classes\defaultFlavor\debug E:\Backups\etc\Tes
tProj2\Test2\build\dependency-cache\defaultFlavor\debug
Error Code:
        1
Output:
        The filename, directory name, or volume label syntax is incorrect.

        at com.android.ide.common.internal.CommandLineRunner.runCmdLine(CommandL
ineRunner.java:98)
        at com.android.ide.common.internal.CommandLineRunner.runCmdLine(CommandL
ineRunner.java:69)
        at com.android.builder.AndroidBuilder.convertByteCode(AndroidBuilder.jav
a:998)
        at com.android.builder.AndroidBuilder$convertByteCode.call(Unknown Sourc
e)
        at com.android.build.gradle.tasks.Dex.doFullTaskAction(Dex.groovy:55)
        at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(In
crementalTask.groovy:96)
        at org.gradle.util.JavaMethod.invoke(JavaMethod.java:62)
        ... 59 more


BUILD FAILED

Total time: 5.923 secs

之后,我收到此错误:

Gradle: Execution failed for task ':Test2:dexDefaultFlavorDebug'.
> Could not call IncrementalTask.taskAction() on task ':Test2:dexDefaultFlavorDebug'

因此,“文件名,目录名称或卷标语法”看起来有问题,但是什么文件?什么目录?

我猜它可能是关于分隔符的东西,但我不确定,我对gradle的掌握很弱。

(我已经设置了路径变量,JAVA_HOME变量和JDK_HOME变量指向我的JDK 7_45目录。我正在运行Win 7。)

编辑:我的Gradle文件看起来像这样

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 17
    buildToolsVersion "19.0.0"

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 17
    }
    buildTypes {
        release {
            runProguard true
            proguardFile getDefaultProguardFile('proguard-android-optimize.txt')
        }
    }
    productFlavors {
        defaultFlavor {
            proguardFile 'proguard-rules.txt'
        }
    }
}

dependencies {
}

2 个答案:

答案 0 :(得分:6)

终于解决了。我再次查看错误消息并尝试在失败前运行最后一个命令,例如:

C:\Android\android-studio2\sdk\build-tools\android-4.4\dx.bat --dex --ou
tput E:\Backups\etc\TestProj2\Test2\build\libs\Test2-defaultFlavor-debug.dex E:\
Backups\etc\TestProj2\Test2\build\classes\defaultFlavor\debug E:\Backups\etc\Tes
tProj2\Test2\build\dependency-cache\defaultFlavor\debug

这给出了“文件名,目录名或卷标语法不正确”。那么我去了build-tools文件夹并运行了没有cmd-line args的dx.bat:

C:\Android\android-studio2\sdk\build-tools\android-4.4\dx.bat

仍然有同样的错误。所以我查看了文件内部并找到了这些行:

rem Check we have a valid Java.exe in the path.
set java_exe=
if exist    "%~dp0..\tools\lib\find_java.bat" call    "%~dp0..\tools\lib\find_java.bat"
if exist "%~dp0..\..\tools\lib\find_java.bat" call "%~dp0..\..\tools\lib\find_java.bat"
if not defined java_exe goto :EOF

所以我尝试从命令行运行find_java.bat而它什么都没有返回

所以我用下面的代码替换了上面的代码:

set java_exe=C:\Windows\System32\java.exe

一切都开始了......

答案 1 :(得分:0)

这是我的解决方案:

运行我的React Native应用程序时出现此错误:

java.io.IOException: The filename, directory name, or volume label syntax is incorrect.

这意味着您在Gradle中遇到问题。然后,我进入build-tools文件夹并运行dx.bat,没有cmd行参数

C:\Android\build-tools\30.0.1\dx.bat

(位于SDK中)。

在记事本或任何编辑器或IDE中打开此文件。您在下面找到此行代码的位置

rem Check we have a valid Java.exe in the path.
set java_exe=
if exist    "%~dp0..\tools\lib\find_java.bat" call    "%~dp0..\tools\lib\find_java.bat"
if exist "%~dp0..\..\tools\lib\find_java.bat" call "%~dp0..\..\tools\lib\find_java.bat"
if not defined java_exe goto :EOF

将此代码替换为以下代码:

set java_exe= C:\Program Files\Java\jdk1.8.0_211\bin\java.exe

jre 8更新后,位置java.exe更改了。 在jre 8中从java.exe中删除了c:\windows\system32

我希望它现在可以正常工作。