我想做一些基本的函数。我正在命令行中运行/构建它。我在看用户指南。还有,做一些简单的任务。

当我开始运行简单的任务时,它被成功构建。但是,在一段时间后,它会显示“它目前正在被另一个Gradle实例使用”,并变成BUILD FAILED。我正在使用终端运行任务。那时候我什么都没做。

如果我关闭产生错误的终端,这个问题就解决了。但是,我知道这不是解决办法。

为什么这个错误经常出现?

如何解决?

并且,请参考任何链接来提高我对Android中Gradle Build系统的知识。


当前回答

我被这个错误所困扰,不得不删除用户的.gradle/caches/文件夹的内容和项目的.gradle/文件夹的内容才能继续运行。

不知道是什么引起的,可能是一个失败的构建,使这些文件处于锁定状态?

其他回答

这可能是因为Android Studio的实例不止一个。

在@Sean Stayns的回答中引用了一个场景,以防它能帮助到任何人:如果你把你的项目保存在谷歌Drive文件夹中——不要这样做。只需将项目移动到本地驱动器即可解决此问题。

In the case we were trying to solve, were were also getting the "It is currently in use by another Gradle instance" error and nothing we tried here worked. The process ID was unknown as well. It didn't immediately occur to me to ask where the project was being saved, so in case anyone new to Android Dev is saving their projects to a Google Drive folder, just move over to your local drive. I would have just left this as a comment in @Sean Stayns's answer, but I can't comment. Hopefully it benefits someone.

非常简单的解决方案:

不需要杀死Android Studio,只需杀死OpenJdkPlatform进程, 然后删除下面的.lock文件:

rootProject/.gradle/<version>/taskHistory

我也遇到过同样的问题,我做了两步就解决了。

我的JDK没有安装在Mac上(我忘了安装),我安装了它。 我删除了位于这个路径/Users/icon_developer/的缓存文件夹中的所有项目。Gradle /和重建项目。 它工作!

通过执行如下命令删除gradle缓存中的锁文件:

find ~/.gradle -type f -name "*.lock" -delete