我看到人们在编译Android时已经面临Gradle的问题,但似乎没有人面临Gradle正在运行应该处理PNG文件的aapt命令时不时出现的特定问题。
我的环境:
有时每隔3个版本,Gradle .apk生成失败,同时处理应该在最终.apk中发布的PNG文件。
失败的命令如下:
/opt/android-sdk/build-tools/19.1.0/aapt s -i /home/opt/buildAgent/work/bb4757955823a092/myProject/src/main/res/drawable-sw600dp-hdpi/ic_under_18.png -o /home/opt/buildAgent/work/bb4757955823a092/myProject/build/res/all/myFlavor/release/drawable-sw600dp-hdpi/ic_under_18.png
导致Gradle构建失败并出现以下异常(Gradle构建由Ant脚本启动,但直接运行会导致同样的问题),这会导致137错误代码:
[exec] Error: Failed to run command:
[exec] /opt/android-sdk/build-tools/19.1.0/aapt s -i /home/opt/buildAgent/work/bb4757955823a092/myProject/src/main/res/drawable-sw600dp-hdpi/ic_under_18.png -o /home/opt/buildAgent/work/bb4757955823a092/myProject/build/res/all/myFlavor/release/drawable-sw600dp-hdpi/ic_under_18.png
[exec] Error Code:
[exec] 137
[exec]
[exec] :myProject:mergemyFlavorReleaseResources FAILED
[exec]
[exec] FAILURE: Build failed with an exception.
[exec]
[exec] * What went wrong:
[exec] Execution failed for task ':myProject:mergemyFlavorReleaseResources'.
[exec] > Error: Failed to run command:
[exec] /opt/android-sdk/build-tools/19.1.0/aapt s -i /home/opt/buildAgent/work/bb4757955823a092/myProject/src/main/res/drawable-sw600dp-hdpi/ic_under_18.png -o /home/opt/buildAgent/work/bb4757955823a092/myProject/build/res/all/myFlavor/release/drawable-sw600dp-hdpi/ic_under_18.png
[exec] Error Code:
[exec] 137
[exec]
[exec]
[exec] * Try:
[exec] Run with --info or --debug option to get more log output.
[exec]
[exec] * Exception is:
[exec] org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':myProject:mergemyFlavorReleaseResources'.
[exec] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
[exec] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
[exec] at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
[exec] at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
[exec] at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
[exec] at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
[exec] at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
[exec] at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
[exec] at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
[exec] at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:289)
[exec] at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
[exec] at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
[exec] at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
[exec] at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:23)
[exec] at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:86)
[exec] at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
[exec] at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
[exec] at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
[exec] at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
[exec] at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
[exec] at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
[exec] at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
[exec] at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166)
[exec] at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
[exec] at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
[exec] at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
[exec] at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
[exec] at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
[exec] at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
[exec] at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
[exec] at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
[exec] at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
[exec] at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
[exec] at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
[exec] at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
[exec] at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
[exec] at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
[exec] at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
[exec] at org.gradle.launcher.Main.doAction(Main.java:46)
[exec] at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
[exec] at org.gradle.launcher.Main.main(Main.java:37)
[exec] at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
[exec] at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
[exec] at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
[exec] Caused by: com.android.build.gradle.tasks.ResourceException: Error: Failed to run command:
[exec] /opt/android-sdk/build-tools/19.1.0/aapt s -i /home/opt/buildAgent/work/bb4757955823a092/myProject/src/main/res/drawable-sw600dp-hdpi/ic_under_18.png -o /home/opt/buildAgent/work/bb4757955823a092/myProject/build/res/all/myFlavor/release/drawable-sw600dp-hdpi/ic_under_18.png
[exec] Error Code:
[exec] 137
[exec]
[exec] at com.android.build.gradle.tasks.MergeResources.doFullTaskAction(MergeResources.groovy:96)
[exec] at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.groovy:70)
[exec] at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
[exec] at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:236)
[exec] at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:212)
[exec] at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:223)
[exec] at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:201)
[exec] at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:533)
[exec] at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:516)
[exec] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
[exec] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
[exec] ... 43 more
[exec] Caused by: Error: Failed to run command:
[exec] /opt/android-sdk/build-tools/19.1.0/aapt s -i /home/opt/buildAgent/work/bb4757955823a092/myProject/src/main/res/drawable-sw600dp-hdpi/ic_under_18.png -o /home/opt/buildAgent/work/bb4757955823a092/myProject/build/res/all/myFlavor/release/drawable-sw600dp-hdpi/ic_under_18.png
[exec] Error Code:
[exec] 137
[exec]
[exec] at com.android.ide.common.res2.MergeWriter.end(MergeWriter.java:53)
[exec] at com.android.ide.common.res2.MergedResourceWriter.end(MergedResourceWriter.java:111)
[exec] at com.android.ide.common.res2.DataMerger.mergeData(DataMerger.java:249)
[exec] at com.android.ide.common.res2.ResourceMerger.mergeData(ResourceMerger.java:25)
[exec] at com.android.build.gradle.tasks.MergeResources.doFullTaskAction(MergeResources.groovy:89)
[exec] ... 53 more
[exec] Caused by: com.android.ide.common.internal.LoggedErrorException: Failed to run command:
[exec] /opt/android-sdk/build-tools/19.1.0/aapt s -i /home/opt/buildAgent/work/bb4757955823a092/myProject/src/main/res/drawable-sw600dp-hdpi/ic_under_18.png -o /home/opt/buildAgent/work/bb4757955823a092/myProject/build/res/all/myFlavor/release/drawable-sw600dp-hdpi/ic_under_18.png
[exec] Error Code:
[exec] 137
[exec]
[exec] at com.android.ide.common.internal.CommandLineRunner.runCmdLine(CommandLineRunner.java:98)
[exec] at com.android.ide.common.internal.AaptCruncher.crunchPng(AaptCruncher.java:58)
[exec] at com.android.ide.common.res2.MergedResourceWriter$1.call(MergedResourceWriter.java:185)
[exec] at com.android.ide.common.res2.MergedResourceWriter$1.call(MergedResourceWriter.java:136)
[exec]
[exec]
[exec] BUILD FAILED
一旦出现问题,如果我运行失败的命令,即
/opt/android-sdk/build-tools/19.1.0/aapt s -i /home/opt/buildAgent/work/bb4757955823a092/myProject/src/main/res/drawable-sw600dp-hdpi/ic_under_18.png -o /home/opt/buildAgent/work/bb4757955823a092/myProject/build/res/all/myFlavor/release/drawable-sw600dp-hdpi/ic_under_18.png
我无法让它失败。 Android Build Tools v19.0.3也会出现此问题。我需要提一下,没有其他构建同时运行,因为我首先怀疑问题是由于并发访问(根据我的说法,不太可能是根本原因)
我有点绝望,因为具有完全相同条件的相同构建(Gradle构建在开始时使用' clean'任务运行),有时会成功,有时会失败。
有没有人(Xavier Ducrochet?)有线索或解决方法,好吗?请告诉我,我是否不够清楚,或者是否缺少重要信息。
感谢您的时间和帮助。问候。
最终执行以下Gradle:
/opt/gradle-1.11/bin/gradle --stacktrace clean myRelease
以下是我的gradle.build文件的摘录,该文件非常繁重,我无法公开:
apply plugin: 'android'
buildscript
{
repositories
{
mavenCentral()
jcenter()
}
dependencies
{
classpath 'com.android.tools.build:gradle:0.9.+'
classpath 'org.gradle.api.plugins:gradle-nexus-plugin:0.7'
}
}
android
{
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig
{
minSdkVersion 14
targetSdkVersion 19
}
}
我希望这有助于理解这个奇怪的问题。我真的很想知道这个问题是不是直接来自aapt ...
答案 0 :(得分:0)
在从Ant?调用Gradle生成之前,您是否尝试执行干净任务?如果您可以提供build.gradle文件内容,请尝试。当你可以使用Gradle时为什么还在使用Ant?