Error:Timeout waiting to lock buildscript class ca

2019-01-17 19:08发布

问题:

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 ?

回答1:

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.



回答2:

File > Invalidate cache / restart

works for me!!!



回答3:

Close android studio and delete anything in cache



回答4:

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.



回答5:

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



回答6:

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



回答7:

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