Java 错误:更改 minSdkVersion 时等待锁定构建文件的构建脚本类缓存超时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31784132/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 11:37:20  来源:igfitidea点击:

Error:Timeout waiting to lock buildscript class cache for build file when change minSdkVersion

javaandroidandroid-studiogradle

提问by user3499878

I try to change minSdkVersionin build.gradle(Module: app) in Android Studioand get next error:

我尝试minSdkVersionbuild.gradle(Module: app) 中更改Android Studio并收到下一个错误:

Error:Timeout waiting to lock buildscript class cache for build file 'E:\pathtoproject\app\build.gradle' (C:\Users\Administrator\.gradle\caches.2.1\scripts\build_f00bwdji3qxl7urq5chsbakgv\ProjectScript\buildscript). It is currently in use by another Gradle instance.
Owner PID: unknown
Our PID: 4592
Owner Operation: unknown
Our operation: Initialize cache
Lock file: C:\Users\Administrator\.gradle\caches.2.1\scripts\build_f00bwdji3qxl7urq5chsbakgv\ProjectScript\buildscript\cache.properties.lock

What is it error? How to change minSdkVersion?

这是什么错误?怎么改minSdkVersion

回答by mcarlin

This sounds like it's related to https://issues.gradle.org/browse/GRADLE-2795.

这听起来像是与https://issues.gradle.org/browse/GRADLE-2795有关。

The easiest way to solve this will be to delete everything under C:\Users\Administrator\.gradle\caches. There is a cache.properties.lockthat is holding a global lock which is preventing you from running your script.

解决此问题的最简单方法是删除C:\Users\Administrator\.gradle\caches. 有一个cache.properties.lock持有全局锁,阻止您运行脚本。

For Mac OSX the folder is located in ~/.gradle/caches. The Android Studio should show the proper path to the file which is causing the lock anyway.

对于 Mac OSX,该文件夹位于~/.gradle/caches. Android Studio 应该显示导致锁定的文件的正确路径。

回答by Medo

Close android studio and delete anything in cache

关闭android studio并删除缓存中的任何内容

回答by IgorGanapolsky

Your build.gradlefile likely contains multiple statements of minSdkVersion. Possibly in defaultConfig{}block and productFlavors{}block. Make sure you are only declaring minSdkVersion oncein the build file.

您的build.gradle文件可能包含多个 minSdkVersion. 可能在defaultConfig{}块和productFlavors{}块中。确保您只在构建文件中声明 minSdkVersion一次

回答by Madhava Rao

1.Check whether multiple instance of java.exerunning then find out why they are running in my case i have opened command prompt it need java instance. open task manager and end task of cmd.exeIf you don't want it to further happen remove path from environment variables and use embedded android studio JDK.

1.检查java.exe的多个实例是否正在运行然后找出它们为什么在我的情况下运行我已经打开命令提示符它需要java实例。打开任务管理器并结束cmd.exe任务 如果您不希望它进一步发生,请从环境变量中删除路径并使用嵌入式 android studio JDK。

2.Delete lock file in /.gradle/cache goto task manager and close all instance of java.exe In android studio click on file invalidate caches/restart

2.Delete lock file in /.gradle/cache goto task manager 并关闭java.exe的所有实例在android studio中点击文件无效缓存/重启

回答by Yog

Sometimes it was notable to delete filehash.lock file and it will throw an error unable to delete file. So do the following steps

有时删除 filehash.lock 文件是值得注意的,它会抛出无法删除文件的错误。所以执行以下步骤

For Windows machine:

对于 Windows 机器:

Open Task Manager(Ctrl-Alt-Delete and check Process)

打开任务管理器(Ctrl-Alt-Delete 并检查进程)

-> If you run two instance of android studio, Close One (End Task)

-> 如果您运行两个 android studio 实例,请关闭一个(结束任务)

-> Then close OpenJDK Platform Binary

-> 然后关闭 OpenJDK Platform Binary

-> Gradle sync now on AndroidStudio and it will work now

-> Gradle 现在在 AndroidStudio 上同步,它现在可以工作了

回答by Lokesh

File > Invalidate cache / restart

文件 > 使缓存无效/重新启动

works for me!!!

对我有用!!!

enter image description here

在此处输入图片说明

回答by AFGhazy

What worked for me:

什么对我有用:

projectPath=[yourProjectPath]
find $projectPath/.gradle -name '*.lock' -delete

You can also remove them one by one:

你也可以一一删除:

gradleVersion=[yourProjectGradleVersion]
projectPath=[yourProjectPath]
rm -f $projectPath/.gradle/$gradleVersion/taskHistory/taskHistory.lock $projectPath/.gradle/$gradleVersion/fileHashes/fileHashes.lock $projectPath/.gradle/$gradleVersion/fileContent/fileContent.lock $projectPath/.gradle/$gradleVersion/javaCompile/javaCompile.lock $projectPath/.gradle/buildOutputCleanup/buildOutputCleanup.lock 

回答by Swapnil Ingle

This worked for me.

这对我有用。

kill all instances of the gradle process.

杀死 gradle 进程的所有实例。

ps -ef | grep gradle

ps -ef | grep gradle

delete the 'Lock file'

删除“锁定文件”

rm C:\Users\Administrator\.gradle\caches\2.2.1\scripts\build_f00bwdji3qxl7urq5chsbakgv\ProjectScript\buildscript\cache.properties.lock

rm C:\Users\Administrator\.gradle\caches\2.2.1\scripts\build_f00bwdji3qxl7urq5chsbakgv\ProjectScript\buildscript\cache.properties.lock

Thanks,

谢谢,

回答by Arthur Valle

For me the only thing that worked was deleting these things inside android folder:

对我来说,唯一有效的是删除 android 文件夹中的这些东西:

  • {appname}.iml
  • .idead/
  • .gradle/buildOutputCleanup/
  • {应用名称}.iml
  • 。我死了/
  • .gradle/buildOutputCleanup/

Posting this for myself 2 weeks from now

从现在起 2 周后为自己发布此信息

回答by Roman K

The lock file is there because some other gradle process (usually the daemon) is using the cache. You could stop all gradle processes to release the lock

锁定文件在那里是因为其他一些 gradle 进程(通常是守护进程)正在使用缓存。您可以停止所有 gradle 进程以释放锁

gradle --stop

https://docs.gradle.org/current/userguide/gradle_daemon.html#sec:stopping_an_existing_daemon

https://docs.gradle.org/current/userguide/gradle_daemon.html#sec:stopping_an_existing_daemon