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

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

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

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

如何解决?

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


当前回答

Mac用户:

你需要给gradle许可:

sudo gradle

其他回答

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

我没有必要删除任何文件来修复这个错误。

我遇到的问题是Gradle实例挂起了,并且在我的任务列表中有6个命令提示项,这些命令提示项是由Java生成的。

强制关闭命令提示符实例允许我像往常一样继续工作。

每个人最后, 我有完整的解决方案

Error :- Timeout Gradle cashe its running in other gradle


distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

Please add this Line in Wrapper.Propertis and Sync now
After Sync the project When 
Invalidthcast\restart   to get the requesting componants

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

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

在@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.