問題描述
我正在嘗試重建我的 Android Studio Gradle 項目(主要包含 Kotlin 代碼),但它在清理/重建過程中開始拋出 UnableToDeleteFileException
:
I'm trying to rebuild my Android Studio Gradle project (containing mostly Kotlin code), but it started to throw an UnableToDeleteFileException
during the cleaning/rebuilding process:
Execution failed for task ':app:clean'.
> Unable to delete file: C:UsersUserKotlinGameEngineappuildintermediatesexploded-aarcom.android.supportappcompat-v723.0.1jarsclasses.jar
這在我嘗試更改項目的包結構后開始發生.不幸的是,我通過重命名和移動源文件夾而不是通過 Android Studio 重構來做到這一點,這是一個壞主意.
This started happening after I tried to change my project's package structure. Unfortunately, I did it by renaming and moving the source folders rather than refactoring through Android Studio, which was a bad idea.
我整天都在尋找解決這個問題的方法,這些都是我嘗試過但無濟于事的事情:
I've been searching for a solution to this problem all day, and these are the things I have tried to no avail:
- 進行 Gradle 同步;
- 重新安裝 Java JRE 和 Java SDK;
- 重新安裝最新版本的 Android Studio (1.4);
- 回滾到之前的 AS 版本 (1.3);
- 使AS緩存失效并重啟;
- 刪除項目目錄下的
gradle
和.gradle
目錄; - 刪除我的用戶目錄下的
.gradle
目錄; - 從 AS 終端運行
gradlew clean
; - 手動將源代碼復制到新項目中(奇怪的是它會以某種方式跨項目持續存在...)
我嘗試了一些成功的事情,但只讓我在錯誤再次發生之前再執行一次清理和重建:
Things that I've tried with a little success, but only let me perform one more clean and rebuild before the error occurs again:
- 關閉AS,手動刪除構建文件,再次打開;
- 在 AS 運行時殺死
java.exe
進程(從技術上講,每次都可以這樣做,但它很乏味并且會減慢構建過程)
- Closing AS, manually deleting the build files, and opening it again;
- Killing the
java.exe
process while AS is running (this could technically be done every time, but it's tedious and slows down the build process)
所以看起來編譯 Java 進程可能會出于某種原因鎖定構建文件,但它也可能與 Kotlin 有關.我有一個(更成熟的)Java Android 項目,我正在處理它,但在清理它時我無法重現此錯誤.這似乎只發生在我的 Kotlin 項目中.
So it seems that compile the Java process may put a lock on the build files for some reason, but it might also be something to do with Kotlin. I have a (more mature) Java Android project that I'm working on, though I can't reproduce this error when cleaning it. It seems to only happen to my Kotlin project.
我發現問題是由 Kotlin Android 插件引起的.當我從模塊的 build.gradle
文件中刪除 apply plugin: 'kotlin-android'
并在我重新插入時又回來了,問題就消失了.隨時提供對此的任何見解.
I've found that the problem is being caused by the Kotlin Android plugin. The problem disappears when I remove apply plugin: 'kotlin-android'
from the module's build.gradle
file and comes back when I reinsert it. Feel free to offer any insight into this.
最后一次更新不是原因.我發現如果一個項目包含一個 Kotlin 文件,那么重建和清理就會失敗.即使刪除了所有 Kotlin 文件,它也會繼續失敗,直到后臺 Java 進程被殺死,這意味著它對構建文件有某種鎖定.我在這里提交了一個錯誤,其中包含更多詳細信息和重現錯誤的步驟:KT-9440
The last update isn't the cause. I found that if a project contains a Kotlin file then rebuilding and cleaning fails. It continues to fail, even if all the Kotlin files are removed, until the background Java process is killed, meaning it has some kind of lock on the build files. I submitted a bug here with more details and steps to reproduce the bug: KT-9440
推薦答案
試試文件 -> 使緩存無效并重新啟動
Try File -> Invalidate Caches and Restart
這對我有用
這篇關于錯誤:任務 ':app:clean' 的執行失敗.無法刪除文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!