Clearing Lock Files from Your Caches
Here ’s a quick tip that can help after a Gradle build is interrupted.
Gradle uses locks to ensure only one process accesses a resource at a time. If a build is interrupted, it may not have a chance to remove those lock files, which can prevent subsequent builds from accessing the same resources.
On my machine, Android Studio detects the first lock file after a minute or so. After I delete it manually and restart the build, it often reports another lock file. Removing that one and repeating the process eventually clears all leftover locks.
I ’m assuming you ’re only building one project at a time.
There are two directories that need to be cleared of lock files:
- the
.gradledirectory in your home directory, and - the
.gradledirectory inside your project.
To remove lock files from the home .gradle directory:
find ~/.gradle/ -name "*.lock" | xargs rmTo remove lock files from a project .gradle directory, change the path accordingly:
find /Path/To/MyProject/.gradle -name "*.lock" | xargs rmAfter this, trigger your Gradle build again; it should run at normal speed.
Hope that helps!
Thank you for reading!