简体   繁体   中英

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

I try to change minSdkVersion in build.gradle (Module: app) in Android Studio and get next error:

Error:Timeout waiting to lock buildscript class cache for build file 'E:\pathtoproject\app\build.gradle' (C:\Users\Administrator\.gradle\caches\2.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.2.1\scripts\build_f00bwdji3qxl7urq5chsbakgv\ProjectScript\buildscript\cache.properties.lock

What is it error? How to change minSdkVersion ?

This sounds like it's related to 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.lock that is holding a global lock which is preventing you from running your script.

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.

File > Invalidate cache / restart

works for me!!!

在此处输入图片说明

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 --stop

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

1.Check whether multiple instance of java.exe running 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.exe If you don't want it to further happen remove path from environment variables and use embedded 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

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

for me, it solved the problem by killing the PID

  • Windows taskkill /F /PID pid_number
  • Linux kill -9 pid_number

This worked for me.

kill all instances of the gradle process.

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

Thanks,

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 

从 / 中删除 .gradle 文件夹并从项目中重新同步 gradle。

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

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

For Windows machine:

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

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

-> Then close OpenJDK Platform Binary

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

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

  • {appname}.iml
  • .idead/
  • .gradle/buildOutputCleanup/

Posting this for myself 2 weeks from now

Issue: If you open two Android Studios, and two of them are using Camera Services to capture image then we you face this issue.

Solution: Close One Android Studio.

For A novice like me, who encountered the situation for the first time and was not able to delete the .lock file or the .gradle folder,

In windows 10 or others, restart the pc using safe mode,(windows key + R ---> msconfig ----> select boot, boot in safe mode----> restart) then delete the files, (this should delete the files and folder)

then in normal mode, restart android studio and sync gradle to download the appropriate version (hopefully the project should work now)

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

You should delete the file in this extension. Then you will see that the problem is fixed. I lived the same problem.

I have got the same issue:

在此处输入图片说明

To resolve this issue, kill the process which retain the journal with kill -9 command

Log explain perfectly which process is involved in your issue, so you can retrieve the PID or the file path concerned

In this example, the command will be:

kill -9 0739

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM