有时在遇到一些隐蔽的错误导致编译出错,但是AS并没有给出明确提示,最常见的就是资源问题,下面提供一种方式来排查问题。
工程目录下运行下面一行命令
gradlew build --stacktrace --debug
将得到输出,比如:
11:20:19.007 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Process 'command '/usr/local/Cellar/android-sdk/24.4.1_1/build-tools/24.0.1/aapt'' finished with exit value 1 (state: FAILED)
11:20:19.023 [INFO] [org.gradle.api.Project] /Users/apple/work/dy_cike/dy_cike_cikechuanshuo_init_init/android/build/intermediates/assets/debug/particle/粒子编辑列表.xlsx: error: Invalid filename. Unable to add.
11:20:19.026 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':android:processDebugResources'
11:20:19.026 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :android:processDebugResources FAILED
11:20:19.028 [INFO] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] :android:processDebugResources (Thread[Task worker Thread 2,5,main]) completed. Took 0.285 secs.
11:20:19.028 [DEBUG] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] Task worker [Thread[Task worker Thread 2,5,main]] finished, busy: 0.523 secs, idle: 1.069 secs
11:20:19.028 [DEBUG] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] Task worker [Thread[Daemon worker,5,main]] finished, busy: 1.07 secs, idle: 0.512 secs
11:20:19.028 [DEBUG] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] Task worker [Thread[Task worker,5,main]] finished, busy: 0.343 secs, idle: 1.253 secs
11:20:20.757 [ERROR] [system.err] Note: /Users/apple/work/df_lib_gradle/lib_core/src/df/util/type/TimeUtil.java uses or overrides a deprecated API.
11:20:20.757 [ERROR] [system.err] Note: Recompile with -Xlint:deprecation for details.
11:20:20.758 [ERROR] [system.err] Note: Some input files use unchecked or unsafe operations.
11:20:20.758 [ERROR] [system.err] Note: Recompile with -Xlint:unchecked for details.
11:20:20.759 [ERROR] [system.err] 1 warning
11:20:20.793 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':lib_core:compileJava'
11:20:20.794 [INFO] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] :lib_core:compileJava (Thread[Task worker Thread 3,5,main]) completed. Took 3.344 secs.
11:20:20.794 [DEBUG] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] Task worker [Thread[Task worker Thread 3,5,main]] finished, busy: 3.344 secs, idle: 0.012 secs
11:20:20.805 [ERROR] [org.gradle.BuildExceptionReporter]
11:20:20.811 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
11:20:20.811 [ERROR] [org.gradle.BuildExceptionReporter]
11:20:20.811 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
11:20:20.811 [ERROR] [org.gradle.BuildExceptionReporter] Execution failed for task ':android:processDebugResources'.
11:20:20.812 [ERROR] [org.gradle.BuildExceptionReporter] > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/local/Cellar/android-sdk/24.4.1_1/build-tools/24.0.1/aapt'' finished with non-zero exit value 1
11:20:20.812 [ERROR] [org.gradle.BuildExceptionReporter]
11:20:20.812 [ERROR] [org.gradle.BuildExceptionReporter] * Exception is:
11:20:20.813 [ERROR] [org.gradle.BuildExceptionReporter] org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':android:processDebugResources'.
11:20:20.813 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
11:20:20.813 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
11:20:20.814 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
11:20:20.814 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:66)
11:20:20.814 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
11:20:20.814 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
11:20:20.814 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
11:20:20.814 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
11:20:20.815 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
11:20:20.815 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:203)
11:20:20.815 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:185)
11:20:20.815 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:66)
11:20:20.816 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:50)
11:20:20.816 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
11:20:20.816 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
11:20:20.816 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/local/Cellar/android-sdk/24.4.1_1/build-tools/24.0.1/aapt'' finished with non-zero exit value 1
11:20:20.816 [ERROR] [org.gradle.BuildExceptionReporter] at com.android.build.gradle.tasks.ProcessAndroidResources.doFullTaskAction(ProcessAndroidResources.java:207)
11:20:20.816 [ERROR] [org.gradle.BuildExceptionReporter] at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.java:82)
11:20:20.817 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
11:20:20.817 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:245)
11:20:20.817 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:221)
11:20:20.817 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:232)
11:20:20.817 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:210)
11:20:20.817 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
11:20:20.818 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
11:20:20.818 [ERROR] [org.gradle.BuildExceptionReporter] ... 14 more
11:20:20.818 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/local/Cellar/android-sdk/24.4.1_1/build-tools/24.0.1/aapt'' finished with non-zero exit value 1
11:20:20.818 [ERROR] [org.gradle.BuildExceptionReporter] at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:43)
11:20:20.818 [ERROR] [org.gradle.BuildExceptionReporter] at com.android.builder.core.AndroidBuilder.processResources(AndroidBuilder.java:983)
11:20:20.818 [ERROR] [org.gradle.BuildExceptionReporter] at com.android.build.gradle.tasks.ProcessAndroidResources.doFullTaskAction(ProcessAndroidResources.java:163)
11:20:20.818 [ERROR] [org.gradle.BuildExceptionReporter] ... 22 more
11:20:20.819 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: org.gradle.process.internal.ExecException: Process 'command '/usr/local/Cellar/android-sdk/24.4.1_1/build-tools/24.0.1/aapt'' finished with non-zero exit value 1
11:20:20.819 [ERROR] [org.gradle.BuildExceptionReporter] at org.gradle.process.internal.DefaultExecHandle$ExecResultImpl.assertNormalExitValue(DefaultExecHandle.java:367)
11:20:20.819 [ERROR] [org.gradle.BuildExceptionReporter] at com.android.build.gradle.internal.process.GradleProcessResult.assertNormalExitValue(GradleProcessResult.java:41)
11:20:20.819 [ERROR] [org.gradle.BuildExceptionReporter] ... 24 more
11:20:20.819 [ERROR] [org.gradle.BuildExceptionReporter]
11:20:20.819 [LIFECYCLE] [org.gradle.BuildResultLogger]
11:20:20.820 [LIFECYCLE] [org.gradle.BuildResultLogger] BUILD FAILED
11:20:20.820 [LIFECYCLE] [org.gradle.BuildResultLogger]
11:20:20.820 [LIFECYCLE] [org.gradle.BuildResultLogger] Total time: 20.249 secs
11:20:20.846 [DEBUG] [org.gradle.cache.internal.btree.BTreePersistentIndexedCache] Closing cache taskArtifacts.bin (/Users/apple/work/dy_cike/dy_cike_cikechuanshuo_init_init/.gradle/2.14.1/taskArtifacts/taskArtifacts.bin)
11:20:20.847 [DEBUG] [org.gradle.cache.internal.btree.BTreePersistentIndexedCache] Closing cache fileSnapshotsToTreeSnapshotsIndex.bin (/Users/apple/work/dy_cike/dy_cike_cikechuanshuo_init_init/.gradle/2.14.1/taskArtifacts/fileSnapshotsToTreeSnapshotsIndex.bin)
11:20:20.847 [DEBUG] [org.gradle.cache.internal.btree.BTreePersistentIndexedCache] Closing cache fileSnapshots.bin (/Users/apple/work/dy_cike/dy_cike_cikechuanshuo_init_init/.gradle/2.14.1/taskArtifacts/fileSnapshots.bin)
11:20:20.848 [DEBUG] [org.gradle.cache.internal.btree.BTreePersistentIndexedCache] Closing cache fileHashes.bin (/Users/apple/work/dy_cike/dy_cike_cikechuanshuo_init_init/.gradle/2.14.1/taskArtifacts/fileHashes.bin)
11:20:20.848 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] Releasing lock on task history cache (/Users/apple/work/dy_cike/dy_cike_cikechuanshuo_init_init/.gradle/2.14.1/taskArtifacts).
11:20:20.849 [DEBUG] [org.gradle.api.internal.artifacts.ivyservice.ivyresolve.memcache.InMemoryCachedRepositoryFactory] In-memory dependency metadata cache closed. Repos cached: 33, cache instances: 8, modules served from cache: 31, artifacts: 11
11:20:20.849 [DEBUG] [org.gradle.cache.internal.DefaultCacheAccess] Cache Generated Gradle JARs cache (/Users/apple/.gradle/caches/2.14.1/generated-gradle-jars) was closed 0 times.
在AS执行clean project操作,返回红色高亮错误
Error:Execution failed for task ':android:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/local/Cellar/android-sdk/24.4.1_1/build-tools/24.0.1/aapt'' finished with non-zero exit value 1
执行下面这行命令,获取详细出错信息
gradlew android:processDebugResources --info
查看日志,发现是资源里有中文引起编译错误。将这些文件改成英文名称。
Successfully started process 'command '/usr/local/Cellar/android-sdk/24.4.1_1/build-tools/23.0.2/aapt''
/Users/apple/work/dy_cike/dy_cike_cikechuanshuo_init_init/android/build/intermediates/assets/debug/particle/粒子编辑列表.xlsx: error: Invalid filename. Unable to add.
:android:processDebugResources FAILED
:android:processDebugResources (Thread[Task worker Thread 2,5,main]) completed. Took 0.081 secs.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':android:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/local/Cellar/android-sdk/24.4.1_1/build-tools/23.0.2/aapt'' finished with non-zero exit value 1
转载自:https://blog.csdn.net/wulong710/article/details/52649248
更新:或者直接使用命令
gradlew compileDebugSources
gradlew assembleDebug --stacktrace