【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

在這裏插入圖片描述

二、解決方案

經過一番嘗試和搜索,終於找到了類似問題,發現瞭解決方案,原來是 Instant Run 的鍋,設置裏關閉就好了。
在這裏插入圖片描述

三、問題原因

據 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.