【Android】Failed to capture snapshot of output files for task

本文环境:

  • Android Studio 3.0.1
  • Gradle version 4.6
  • Android Plugin Version 3.0.1

一、问题描述

新建了一个 Android 项目,minSdkVersion 选的 21(Android 5.0),啥都没改呢就编译报错,很是诡异,如图所示

Gradle tasks [:app:assembleDebug]
Failed to capture snapshot of output files for task 'transformClassesWithDexBuilderForDebug' property 'streamOutputFolder' during up-to-date check.
> Failed to create MD5 hash for file 'C:\User\Administrator\Desktop\android\MyApplication\app\build\intermediates\transforms\dexBuilder\debug\6.jar'.
BUILD FAILED in 4s
1 error
0 warnings
See complete output in console

【Android】Failed to capture snapshot of output files for task

二、解决方案

经过一番尝试和搜索,终于找到了类似问题,发现了解决方案,原来是 Instant Run 的锅,设置里关闭就好了。
【Android】Failed to capture snapshot of output files for task

三、问题原因

据 Stack Overflow 描述,貌似是 gradle 的问题,还有一种可能就是杀毒软件的问题

The issue in the latest android studio update is with the Instant Run feature. There happens to be a serious issue with gradle, so you may either turn off the Anti-Virus or the Instant Run feature till then.