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

JavaAndroidAndroid StudioGradle

Java Problem Overview


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 ?

Java Solutions


Solution 1 - Java

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.

Solution 2 - Java

> File > Invalidate cache / restart

works for me!!!

enter image description here

Solution 3 - Java

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

Solution 4 - Java

for me, it solved the problem by killing the PID

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

Solution 5 - Java

I have got the same issue:

enter image description here

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 9739

Solution 6 - Java

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

Solution 7 - Java

Close android studio and delete anything in cache

Solution 8 - Java

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,

Solution 9 - Java

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 

Solution 10 - Java

Delete .gradle folder from / and resync gradle from project.

Solution 11 - Java

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.

Solution 12 - Java

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

Solution 13 - Java

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

Solution 14 - Java

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.

Solution 15 - Java

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)

Solution 16 - Java

"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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser3499878View Question on Stackoverflow
Solution 1 - JavamcarlinView Answer on Stackoverflow
Solution 2 - JavaLokeshView Answer on Stackoverflow
Solution 3 - JavaRoman KView Answer on Stackoverflow
Solution 4 - JavaHenriqueView Answer on Stackoverflow
Solution 5 - JavaKevin ABRIOUXView Answer on Stackoverflow
Solution 6 - JavaMadhava RaoView Answer on Stackoverflow
Solution 7 - JavaMed ElgarnaouiView Answer on Stackoverflow
Solution 8 - JavaSwapnil IngleView Answer on Stackoverflow
Solution 9 - JavaAFGhazyView Answer on Stackoverflow
Solution 10 - JavaAnuj JindalView Answer on Stackoverflow
Solution 11 - JavaIgorGanapolskyView Answer on Stackoverflow
Solution 12 - JavaYogView Answer on Stackoverflow
Solution 13 - JavaArthur ValleView Answer on Stackoverflow
Solution 14 - JavaAmbilpura Sunil KumarView Answer on Stackoverflow
Solution 15 - Java1234567View Answer on Stackoverflow
Solution 16 - JavaMustafa BalinView Answer on Stackoverflow