Gradle 构建不起作用:任务“:MyApp:compileDebug”执行失败
Posted
技术标签:
【中文标题】Gradle 构建不起作用:任务“:MyApp:compileDebug”执行失败【英文标题】:Gradle build not working: Execution failed for task ':MyApp:compileDebug' 【发布时间】:2014-01-31 11:42:58 【问题描述】:我正在尝试将项目迁移到 Gradle,但每次运行命令时都会引发异常
gradle build --stacktrace
我使用的是 Gradle 1.6。这是错误的堆栈跟踪:
:MyApp:compileDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':MyApp:compileDebug'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --info or --debug option to get more log output.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':MyApp:compileDebug'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
at org.gradle.api.internal.changedetection.state.CacheLockReleasingTaskExecuter$1.run(CacheLockReleasingTaskExecuter.java:35)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:179)
at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:232)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:142)
at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:83)
at org.gradle.api.internal.changedetection.state.CacheLockReleasingTaskExecuter.execute(CacheLockReleasingTaskExecuter.java:33)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.ContextualisingTaskExecuter.execute(ContextualisingTaskExecuter.java:34)
at org.gradle.api.internal.changedetection.state.CacheLockAcquiringTaskExecuter$1.run(CacheLockAcquiringTaskExecuter.java:39)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:124)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:112)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:134)
at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:79)
at org.gradle.api.internal.changedetection.state.CacheLockAcquiringTaskExecuter.execute(CacheLockAcquiringTaskExecuter.java:37)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:57)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:41)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:52)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:42)
at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:282)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.executeTask(DefaultTaskPlanExecutor.java:48)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.processTask(DefaultTaskPlanExecutor.java:34)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:27)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:89)
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
at org.gradle.api.internal.changedetection.state.TaskCacheLockHandlingBuildExecuter$1.run(TaskCacheLockHandlingBuildExecuter.java:31)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:124)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:112)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:134)
at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.useCache(DefaultTaskArtifactStateCacheAccess.java:79)
at org.gradle.api.internal.changedetection.state.TaskCacheLockHandlingBuildExecuter.execute(TaskCacheLockHandlingBuildExecuter.java:29)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.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(ExceptionReportingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:48)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.Main.main(Main.java:39)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
at org.gradle.launcher.GradleMain.main(GradleMain.java:26)
Caused by: org.gradle.api.internal.tasks.compile.CompilationFailedException: Compilation failed; see the compiler error output for details.
at org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.execute(Jdk6JavaCompiler.java:42)
at org.gradle.api.internal.tasks.compile.jdk6.Jdk6JavaCompiler.execute(Jdk6JavaCompiler.java:33)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:95)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:48)
at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:34)
at org.gradle.api.internal.tasks.compile.DelegatingJavaCompiler.execute(DelegatingJavaCompiler.java:29)
at org.gradle.api.internal.tasks.compile.DelegatingJavaCompiler.execute(DelegatingJavaCompiler.java:20)
at org.gradle.api.internal.tasks.compile.IncrementalJavaCompilerSupport.execute(IncrementalJavaCompilerSupport.java:33)
at org.gradle.api.internal.tasks.compile.IncrementalJavaCompilerSupport.execute(IncrementalJavaCompilerSupport.java:24)
at org.gradle.api.tasks.compile.Compile.compile(Compile.java:68)
at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:216)
at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:122)
at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147)
at org.gradle.api.tasks.compile.JavaCompile_Decorated.invokeMethod(Unknown Source)
at org.gradle.util.ReflectionUtil.invoke(ReflectionUtil.groovy:23)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:217)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:210)
at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:199)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:526)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:509)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
... 67 more
我在 settings.gradle 中定义了以下结构:
include ':MyApp'
include ':Libraries:LibProject1'
include ':Libraries:LibProject2'
include ':Libraries:LibProject3'
include ':Libraries:LibProject4'
而我项目的目录是这样的:
- My Repository
-- settings.gradle
- My App
-- build.gradle
- Libraries
- LibProject1
-- build.gradle
- LibProject2
-- build.gradle
- LibProject3
-- build.gradle
- LibProject4
-- build.gradle
我的应用> build.gradle 文件是这样的:
buildscript
repositories
mavenCentral()
dependencies
classpath 'com.android.tools.build:gradle:0.5.+'
apply plugin: 'android'
dependencies
compile fileTree(dir: 'libs/main', include: '*.jar')
compile project(':Libraries:LibProject1')
compile project(':Libraries:LibProject2')
compile project(':Libraries:LibProject3')
compile project(':Libraries:LibProject4')
android
compileSdkVersion "Google Inc.:Google APIs:19"
buildToolsVersion "19.0.1"
sourceSets
main
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main/java', 'src-gen/main/java', 'generated']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
而所有的LibProject#> build.gradle文件都是这样的:
buildscript
repositories
mavenCentral()
dependencies
classpath 'com.android.tools.build:gradle:0.5.+'
apply plugin: 'android-library'
android
compileSdkVersion 19
buildToolsVersion "19.0.1"
sourceSets
main
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
我已经尝试了在其他线程中找到的几种可能的解决方案,但似乎没有任何效果。
我还将我的项目结构及其所有 .gradle 文件与另一个正在成功构建的项目进行了比较,我找不到任何遗漏。
与我在相关线程中发现的其他问题不同,这里的堆栈跟踪似乎没有提供任何关于引发异常的具体原因。有什么想法吗?
【问题讨论】:
:MyApp:compileDebug
因编译错误而失败,并且应该在某处出现编译器错误消息。 (您不必使用--debug
或--stacktrace
来获取该消息。)
@PeterNiederwieser 我找不到任何编译器错误消息。我得到的只是Execution failed for task ':MyApp:compileDebug'. > Compilation failed; see the compiler error output for details. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
在哪里可以获得更详细的编译器消息?
请问您为什么不使用更新版本的插件? Android-Gradle 插件现在为 0.7.4,Gradle 为 1.9 - 并不是说这对您遇到的问题有影响,但它可能会。
编译器错误消息将在您显示的消息上方的某个位置。对于您的升级问题,请参阅 SO 上的类似问题。
在 build.gradle(文件中的第 6 行)中,您需要将插件的类路径更改为“com.android.tools.build:gradle:0.7.+”。这应该会导致插件寻找正确的 Gradle 版本(对于插件 - 1.9)。
【参考方案1】:
如果您不使用 Android Annotations 但仍然看不到原因,您实际上可以按照消息中的说明执行操作(检查编译器输出),方法是:
转到构建选项卡 将输出切换到编译器输出【讨论】:
哪天我会遇到错误,却不知道有这个出色的按钮,谢谢! 我为 Android 开发已经 7 年了,但是每次我遇到问题时,我都不关心这个按钮,谢谢【参考方案2】:我终于找到了问题所在。该项目使用 Android Annotations,我已将其生成的源文件夹包含在我的 build.gradle 文件中。
当 Gradle 再次尝试生成源时,会因为类重复而失败。
这是正确的 build.gradle:
buildscript
repositories
mavenCentral()
dependencies
classpath 'com.android.tools.build:gradle:0.5.+'
apply plugin: 'android'
dependencies
compile fileTree(dir: 'libs/main', include: '*.jar')
compile project(':Libraries:LibProject1')
compile project(':Libraries:LibProject2')
compile project(':Libraries:LibProject3')
compile project(':Libraries:LibProject4')
android
compileSdkVersion "Google Inc.:Google APIs:19"
buildToolsVersion "19.0.1"
sourceSets
main
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main/java', 'src-gen/main/java']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
【讨论】:
对不起,这个 Gradle 文件的主要区别是什么? @IgorGanapolsky'generated'
文件夹不包含在java.srcDirs
中。
有趣。我遇到了同样的问题,我正在使用 AA,但我在 srcDirs 中没有“生成”文件夹。
@FelipeBari src-gen
是什么?
@IgorGanapolsky 这是一个由其他东西自动生成的类的文件夹。在我的例子中,它存储了所有由 greenDAO 创建的数据库类。以上是关于Gradle 构建不起作用:任务“:MyApp:compileDebug”执行失败的主要内容,如果未能解决你的问题,请参考以下文章
Gradle:由 gradle bootJar 任务创建的 jar 不起作用
gradle 中的 shadow 插件不起作用 - gradle build 不会构建胖 jar