It is currently in use by another Gradle instance
GradleAndroid Gradle-PluginGradle Problem Overview
I'm new to Gradle build system. I want to do some basic functions on it. I'm running/building it in command line. I am referring User guide. And, doing some simple tasks.
When I start to run simple tasks, it was build successfully. But, After some times, it is showing "It is currently in use by another Gradle instance"
and becomes BUILD FAILED
. I'm using a terminal for run the task. I didn't run anything at that time.
If I closed the terminal which generate the error, this problem would be solved. But, I know that it is not the solution for that.
Why is this error coming frequently?
How to solve it?
And, Please refer any link to improve my knowledge on Gradle Build system in Android.
Gradle Solutions
Solution 1 - Gradle
Remove the lock files in the gradle cache by executing something like this:
find ~/.gradle -type f -name "*.lock" -delete
Solution 2 - Gradle
Sometimes fast way comes in a non-elegant deal, there we go:
Find first the # of all gradle process running on
ps -A | grep gradle
After that, get the IDs, Kill 'em all one by one
sudo kill -9 <process ID>
Now you're good ;-)
Solution 3 - Gradle
I was stuck with this error and had to blow away the contents of my user's .gradle/caches/
folder and the contents of my project's .gradle/
folder to get going again.
Not sure what caused it, possibly a failed build that kept these files in a locked state?
Solution 4 - Gradle
gradlew --stop
I had a similar error, running the above command worked for me.
Solution 5 - Gradle
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 6 - Gradle
Just kill java.exe process fix my problem.
-- Edit --
if not fixed then:
- kill OpenJdkPlatform proccess.
if not fixed then:
- remove all ".lock" file from .gradle directory and sub directories (windows: C:\Users\Username\.gradle).
if not fixed then:
- rename or delete .gradle directory and try again.
Solution 7 - Gradle
This may be happening because there is more than just once instance of Android Studio.
Solution 8 - Gradle
That Gradle failure message is usually followed by the relevant process IDs, so it would be
Gradle sync failed: Timeout waiting to lock daemon addresses registry [...].
It is currently in use by another Gradle instance.
Owner PID: 1234
Our PID: 5678
Owner Operation: ...
In order to unlock, just kill the owner process:
sudo kill -9 1234
Solution 9 - Gradle
For MAC machines
Please open the "Activity Monitor" and select the "memory" option and force quiet the Android studio and other running java processes, it will solve this issue.
Solution 10 - Gradle
I could be late but look like quick and efficient solution.
Execute following steps.
- Execute
ps -ef | grep gradle
- Open terminal and move to ~/.gradle/caches path
- Execute
find ~/.gradle -type f -name "*.lock" | while read f; do rm $f; done
- Delete
.gradle
and.idea
folder from Android studio.
It's done.
Solution 11 - Gradle
Having the same issue on a Mac, none of the above worked for me. What worked , though, was opening the Activity Monitor and closing a running java process. I also noticed that an .hprof file was generated, which I deleted. After that, I ran my project and it worked.
Solution 12 - Gradle
I was facing the same issue in my project but I resolved this by invalidating the project, so follow these steps in the android studio
File -> Invalidate Caches / Restart...
Android studio will restart and your problem should be fixed.
Solution 13 - Gradle
I had the same issue on mac:
take care, that your project is NOT on an external hard disk. The location of your project must be on the hard disk with your operating system.
(Building an Ionic app)
Solution 14 - Gradle
sometimes you need to run this code a few times after each build error
for me it takes two times first i get lock error I run this code then again i get the lock error for another file so I run the code again and at the end it works properly.
find ~/.gradle -type f -name "*.lock" -delete
Solution 15 - Gradle
For Windows OS:
I figured it had something to do with a lock file so i simply went to .gradle\buildOutputCleanup in the project folder and deleted the cache.properties.lock file and rebuilt the project. It was working perfectly.
Solution 16 - Gradle
press CTRL + SHIFT + ESC
to open task manager now find OpenJDK
and kill it goto where the error is pointing to like
D:\.gradle\daemon\4.10.1\registry.bin.lock
delete the file and resynce and you're good to go.
Solution 17 - Gradle
I was too stuck with the same thing. But it was sorted soon. Just delete the file:
> D:\.gradle\daemon\6.1.1\registry.bin.lock
also, I've ended OpenJDK from task manager. Idk it helped or not but both of them solved the problem.
Solution 18 - Gradle
It was not necessary for me to remove any files to fix this error.
The issue I had is that Gradle instances had hung and were 6 command prompt entries in my task list that were spawned by Java.
Forcing the command prompt instances to close allowed me to continue work as usual.
Solution 19 - Gradle
Its Work for me for Problem:- >"Error:Timeout waiting to lock jars It is currently in use by another Gradle instance. Owner PID: 6896 Our PID: 5048 Owner Operation: Our operation: Lock"
Solution:-
- close the Android Studio and Open Task manager and end the process java.exe
- open the derectory ....gradle\caches.
- Delete the jar2.lock file.
- Open android Studion and clean the project.
Solution 20 - Gradle
Have tried all this answers, including kill java process, delete .gradle in HOME_DIR and in project dir, restarted Android Studio, and even restarted OS.
It started to work normally only after I launched gradle sync.
Solution 21 - Gradle
Very simple solution:
no need to kill Android Studio
, just Kill OpenJdkPlatform
process,
then delete the .lock
file located in:
rootProject/.gradle/<version>/taskHistory
Solution 22 - Gradle
While killing the process and/or removing the lock file works, Gradle should be able to handle this on its own, solving the problem permanently. This problem report hints at the solution: Gradle cannot communicate with the gradle service.
Have a look at your local network firewall. In my case,
-
allowing outbound traffic from 127.0.0.1 to 127.0.0.1,
sudo iptables -A OUTPUT -p udp -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT
-
allowing incoming traffic from 127.0.0.1
sudo iptables -A INPUT -s 127.0.0.1 -p udp -j ACCEPT
solved the issue. A discussion of a similar problem at github.
> And, Please refer any link to improve my knowledge on Gradle Build system in Android.
The udacity gradle course, if you have some time.
Solution 23 - Gradle
open terminal and move to project path then run depending on the operation system: gradlew clean or ./gradlew clean
Solution 24 - Gradle
I had same problem and i did two steps and it became solved.
- My JDK was not installed on Mac (i forgot to install) i installed it.
- I deleted all items from caches folder located in this path /Users/icon_developer/.gradle/ and rebuilt the project. It worked!
Solution 25 - Gradle
For Windows Users:
That Gradle failure message is usually followed by the relevant process IDs, so it would be Gradle sync failed: Timeout waiting to lock daemon addresses registry [...]. It is currently in use by another Gradle instance.
Owner PID: 8080
Our PID: 89765
Owner Operation: ...
In order to unlock, just kill the owner process:
taskkill /PID 8080 /F
taskkill /PID 89765 /F
Solution 26 - Gradle
For Mac users on first Gradle sync
I had the same issue when cloning from GitLab using IntelliJ. In fact, as mentioned here : https://stackoverflow.com/a/53269914/2231299 you need to specify an internal hard disk.
So here were the steps in my case:
• Clone locally
• Wait for 1st gradle syncing to perform
• move directory to external hard disk
• reopen project at new location, and then gradle should work fine, even on external hard disk.
Comments: Don't be afraid to re-commit if it looks like the files have some changes. It might just be indentation or line breaks issues, since your external disk might have a different format than your original mac disk.
Solution 27 - Gradle
In my case the culprit was restrictive firewall, part of the antivirus system.
According to the https://discuss.gradle.org/t/timeout-waiting-to-lock-file-hash-cache/21961/2 and https://github.com/elastic/elasticsearch/issues/50954#issuecomment-576772154, gradle-issue-8750, gradle server is keeping the lock and releases it on request of other gradle process. The communication goes over UDP socket on localhost. Thus if there is a firewall blocking this communication, gradle keeps file locks and other gradle processes cannot continue.
Try disabling AV / firewall to see if problem vanishes. Then run gradle as following to get better insight what is going on.
gradle --debug --no-daemon
The debug log shows owner of the lock, if the problem persists, kill the owner of the lock.
2021-05-20T19:32:41.105+0200 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] The file lock is held by a different Gradle process (pid: 67494, lockId: 628651820260732672). Pinged owner at port 58442
2021-05-20T19:32:42.330+0200 [DEBUG] [org.gradle.cache.internal.DefaultFileLockManager] The file lock is held by a different Gradle process (pid: 67494, lockId: 628651820260732672). Pinged owner at port 58442
Then kill -9 67494
terminates the owner and releases the lock.
Otherwise after a while gradle terminates with an error (stating here so it is easy to find):
* What went wrong:
Gradle could not start your build.
> Could not create service of type ResourceSnapshotterCacheService using GradleUserHomeServices.createResourceSnapshotterCacheService().
> Timeout waiting to lock file hash cache (/Users/myusername/.gradle/caches/6.9/fileHashes). It is currently in use by another Gradle instance.
Owner PID: 67494
Our PID: 68313
Owner Operation:
Our operation:
Lock file: /Users/myusername/.gradle/caches/6.9/fileHashes/fileHashes.lock
Solution 28 - Gradle
Citing a scenario to @Sean Stayns's answer in case it helps anyone: If you're saving your projects in a Google Drive folder -- don't. Simply moving the project(s) over to the local drive resolves this problem.
In the case we were trying to solve, were were also getting the "It is currently in use by another Gradle instance" error and nothing we tried here worked. The process ID was unknown as well. It didn't immediately occur to me to ask where the project was being saved, so in case anyone new to Android Dev is saving their projects to a Google Drive folder, just move over to your local drive. I would have just left this as a comment in @Sean Stayns's answer, but I can't comment. Hopefully it benefits someone.
Solution 29 - Gradle
For Mac Users:
you need to give gradle permission:
sudo gradle
Solution 30 - Gradle
Along with the top answers here, you need to figure out why the gradle processes exit without releasing the locks to fix it permanently.
In my case, I did all *.lock file deletions and Android Studio's Invalidate Cache option. But the problem kept coming back.
Running gradlew manually in the terminal showed me that gradle processes prematurely exit when the JVM heap space is exhausted. This answer helped to fix it.
./gradlew build #to detect what crashes gradle processes
./gradlew --stop #to stop any running gradle processes
After fixing the problem (eg: heap exhausted)
find .gradle/ -type f -name "*.lock" -delete #delete lock files
./gradlew build #Try building the project
Solution 31 - Gradle
> org.gradle.cache.LockTimeoutException: Timeout waiting to lock journal > cache (C:\Users\unknown.gradle\caches\journal-1). It is currently in > use by another Gradle instance
I was facing the same issue and I fixed it by opening Task Manger and check running instance of "OpenJDK Platform binary" in background processes except Android Stduio just "End Task" this task and work for me
Solution 32 - Gradle
everyone finally, I have complete solution
Error :- Timeout Gradle cashe its running in other gradle
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Please add this Line in Wrapper.Propertis and Sync now
After Sync the project When
Invalidthcast\restart to get the requesting componants