错误:任务 ':app:clean' 执行失败.无法删除文件 [英] Error: Execution failed for task ':app:clean'. Unable to delete file

查看:45
本文介绍了错误:任务 ':app:clean' 执行失败.无法删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重建我的 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:\Users\User\KotlinGameEngine\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\23.0.1\jars\classes.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' 执行失败.无法删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆