Reputation: 4007
I want to do some basic functions. 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.
Upvotes: 252
Views: 276661
Reputation: 300
For Windows Users, hit the below command in the terminal -
./gradlew --status
Check All the running PIDs and kill/Stop the require PID using below command
./gradlew --stop
Upvotes: 2
Reputation: 1088
If you are using windows, Go to task manager and kill JDK processes.
Upvotes: 1
Reputation: 1698
go to android folder and run.
./gradlew --stop
That's all using mac
Upvotes: 5
Reputation: 4418
With old Flutter project, run with newer version Flutter SDK. You can follow my steps below:
Go to android/build.gradle
update kotlin
and gradle
to new version:
ext.kotlin_version = '1.6.10' >> ext.kotlin_version = '1.7.20'
classpath 'com.android.tools.build:gradle:4.0.1' >> classpath 'com.android.tools.build:gradle:7.1.2'
Next go to android/gradle/wrapper/gradle-wrapper.properties
update:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip >> distributionUrl=https://services.gradle.org/distributions/gradle-7.6-all.zip
After
flutter clean
flutter pub get
// remove lock file
rm /Volumes/T7 Shield/FlutterCodeCanyon/flutter-tiktok-triller-clone-short-video-streaming-mobile-app-for-android-ios/flutter_app/android/.gradle/7.6/dependencies-accessors/dependencies-accessors.lock
// stop gradle
cd android
./gradlew --stop
// or
ps -ef | grep gradle
kill -9 123
Finally run Flutter project again
If you run Project in exFAT SSD on MacOS, maybe error below:
Upvotes: 0
Reputation: 161
Make your $JAVA_HOME
to point to the same JDK version as your Android Studio.
All kudos to Vairavan Srinivasan from Medium
Upvotes: 0
Reputation: 4141
On windows . In Android Studio open Terminal window (used to start in project's root folder) and tipe in
.\gradlew --stop
mine responded:
Welcome to Gradle 7.3.3!
Here are the highlights of this release:
- Easily declare new test suites in Java projects
- Support for Java 17
- Support for Scala 3
For more details see https://docs.gradle.org/7.3.3/release-notes.html
Stopping Daemon(s)
1 Daemon stopped
And now it plays ok with builds and runs as previously
Upvotes: 8
Reputation: 758
Just delete yours .gradle
folder inside android
folder
If it is not available in your File Explorer(WINDOWS)
or Finder(MAC)
For Windows :
go to view
option and check show hidden files
For Mac
just press cmd + shift + .
Now run your app.
Upvotes: 3
Reputation: 484
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
Upvotes: 0
Reputation: 1245
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
Upvotes: 2
Reputation: 52800
I could be late but look like quick and efficient solution.
Execute following steps.
ps -ef | grep gradle
find ~/.gradle -type f -name "*.lock" | while read f; do rm $f; done
.gradle
and .idea
folder from Android studio.It's done.
Upvotes: 6
Reputation: 31
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.
Upvotes: 0
Reputation: 531
gradlew --stop
I had a similar error, running the above command worked for me.
Upvotes: 51
Reputation: 1856
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
Upvotes: 0
Reputation: 89
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.
Upvotes: 6
Reputation: 855
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.
Upvotes: 1
Reputation: 9
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
Upvotes: 0
Reputation: 2583
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.
Upvotes: 11
Reputation: 6623
Remove the lock files in the gradle cache by executing something like this:
find ~/.gradle -type f -name "*.lock" -delete
Upvotes: 644
Reputation: 35
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.
Upvotes: 1
Reputation: 8230
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
Upvotes: 13
Reputation: 4301
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 ;-)
Upvotes: 73
Reputation: 3128
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.
Upvotes: 3
Reputation: 83
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.
Upvotes: 5
Reputation: 9
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
Upvotes: -1
Reputation: 4234
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)
Upvotes: 5
Reputation: 3561
I had same problem and i did two steps and it became solved.
Upvotes: 0
Reputation: 156
open terminal and move to project path then run depending on the operation system: gradlew clean or ./gradlew clean
Upvotes: 0
Reputation: 19
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.
Upvotes: 2
Reputation: 825
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
Upvotes: 18