57
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'oscar'.
> Could not open proj class cache for build file '/Users/prakashv/dev/workspace/oscar-api/build.gradle' (/Users/prakashv/.gradle/caches/2.6/scripts/build_7o20dvaacd2xu3ci3o56uhd4f/proj).
   > Timeout waiting to lock proj class cache for build file '/Users/prakashv/dev/workspace/oscar-api/build.gradle' (/Users/prakashv/.gradle/caches/2.6/scripts/build_7o20dvaacd2xu3ci3o56uhd4f/proj). It is currently in use by another Gradle instance.
     Owner PID: unknown
     Our PID: 47991
     Owner Operation: unknown
     Our operation: Initialize cache
     Lock file: /Users/prakashv/.gradle/caches/2.6/scripts/build_7o20dvaacd2xu3ci3o56uhd4f/proj/cache.properties.lock

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Any idea what the problem could be ? I am using gradle 2.6 and Java 1.8.0_60

premprakash
  • 1,505
  • 3
  • 18
  • 27
  • I had to do this http://stackoverflow.com/questions/21523508/it-is-currently-in-use-by-another-gradle-instance to fix the problem. Had no idea why it happened though. – premprakash Sep 11 '15 at 00:48
  • Did you check to see if you have PID 47991 running? – Ethan Sep 11 '15 at 04:31
  • I got the same problem as the OP after performing a **System Restore** (Windows 7). I noticed that the system restore reverted some javascript files I was working on, so I suspect it has reverted some files in my Android project, too. – ban-geoengineering Oct 21 '17 at 16:32

18 Answers18

36

To solve this I had to first kill the Java(TM) Platform SE binary process and then I was able to delete the whole /Users/<username>/.gradle/caches folder which allowed Gradle commands to work once again.

I believe this issue may have happened for me as a result of adding a new dependency to my build.gradle file through IntelliJ IDEA.

jpierson
  • 16,435
  • 14
  • 105
  • 149
  • 4
    It may not be necessary to delete the whole cache. I only needed to delete the cache mentioned in the error message. It was also not necessary to stop Java. I'd suggest trying minimal disruption first, and then expand it it doesn't work. – Thailandian Mar 10 '17 at 08:47
  • 4
    I deleted both the cache and the folder, there was no result, the error persisted. I restarted the project (development idea) and the error went away, the dependencies were downloaded – S.Daineko Dec 29 '21 at 14:29
19

tl;dr: Try an older JDK


Deleting caches didn't work for me. Deleting the lock files didn't fix it either.

After switching to an older JDK I was able to build my project again.


Idea configured the project to use JDK 14 (preview) but that doesn't seem to work. I set the JDK to 13. Actually the dialogue said it was JDK 13 but somehow from the JDK 14 preview install. So I had to install an actual JDK 13.

m02ph3u5
  • 3,022
  • 7
  • 38
  • 51
7

What @Shriganesh Kolhe said on Apr 22 '17 at 18:12 is roughly 97.3% correct--just a missing \ in the path to navigate to. Corrected/clarified below.

What follows is a generalization of the process since we're all way past gradle release 2.14.1. (Today I'm at 4.1.) And this error will happen again to someone, some day at a higher gradle release.

(1) Locate the folder caches at the end of this path: C:\Users\your_user_name\.gradle\caches\. (For me, this was C:\Users\Dov\.gradle\caches\.)

(2) Find the folder whose name is the LARGEST release number SMALLER than the gradle release being installed. (For me, installing 4.1, this was 3.3.)

(3) For safety, copy the scripts and scripts-remapped folders to safe places.

(4) Then (no worries--you're backed up!) delete all the files in those folders.

(5) Finally build again.

(In the unlikely event that this causes errors, put the moved folders back in place. It worked great for me as outlined.)

DSlomer64
  • 4,234
  • 4
  • 53
  • 88
7

Solution for me was fairly simple:

  • Go to the C:\Users\YOUR_USERNAME\.gradle\caches and locate the subfolder that is being complained about in your error message (e.g., 4.4).
  • Rename that folder (e.g., to 4.4_OLD).
  • Back in Android Studio, do Clean Project then Rebuild Project.

This will then generate a new subfolder (e.g., 4.4) in your caches directory and the build should complete successfully.

ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253
4

I fixed this by increasing total heap size of the Gradle daemon and MetaSpace

org.gradle.jvmargs=-Xmx2048M -XX:MaxMetaspaceSize=512m

inside gradle.properties

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
Yassin Ajdi
  • 1,540
  • 14
  • 13
  • This is the correct answer which works with the latest Gradle and JDK versions. It assumes you are using the Gradle Wrapper and have this file in the roor of your project. – Axel Fontaine Apr 29 '20 at 15:38
3

navigate to C:\Users\user.gradle\caches\2.14.1

move the 'scripts' and 'scripts-remapped'folder to somewhere else. (just in case if something goes wrong)

then try to build again.

It works for me.

3

I've fixed it on Windows.

Open the command prompt, change to the project directory, and clear the gradle cache using the following command.

gradlew clean

This worked for me.

ctt
  • 1,405
  • 8
  • 18
tharindu_b
  • 31
  • 1
3

In my case syncing files using Android Studio helped!

kaxi1993
  • 4,535
  • 4
  • 29
  • 47
3

In my case, I have installed Java 19, The latest java version on my Mac Apple M1 chip. After downgrading it to version 17 my issue is fixed.

I use these commands to uninstall Java 19

sudo rm -rf /Library/Java/JavaVirtualMachines/jdk[version].jdk

sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefPane

sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin

sudo rm -rf ~/Library/Application\ Support/Oracle/Java

And download Java-17 from here

https://www.oracle.com/java/technologies/downloads/#jdk17-mac

ferozpuri
  • 266
  • 2
  • 9
2

go to location

"/Users/prakashv/.gradle/caches/2.6/scripts/build_7o20dvaacd2xu3ci3o56uhd4f/proj/" and remove cache.properties.lock file

2

go to the build folder its pointing and delete the " cacheproperties.lock " files if it shows again a different one this time , delete that too . In my case i did it 2 times .

2

My problem solved by upgrading gradle. because I was using Java 17 but gladle version I was using didn't support it. Checking compatibility matrix for gradle would be useful. you can check it from Compatibility Matrix

You can also check this answer

1

hope my answer will help you. First you should enter the dir "/.gradle/cache/2.x/" and copy the file scripts and scripts-remapped. Then paste them to somewhere else in case of taking place something if you do next. Delete them from the dir "/.gradle/cache/2.x/" finally you should sync the gradle (if everything is OK, Congratulations ) (if not maybe you will find that it will be impossible to establish the initial state so you are supposed to delete the ideal.log(some tips will give you on the top right corner,you can find the path of the ideal.log))

hudezhi
  • 11
  • 1
1

check with jdk version, JDK 16 may causing the issue. You can try to install lower version. I have tried with 11 and 8 jdk and its working. And then rebuild your app.

Dwipal Parmar
  • 244
  • 2
  • 8
1

I figured out something, if you are working on Flutter you can just open the build.gradle Open for Editing in Android Studio then wait for 3-5 minutes. Now try again to get the sha1 key (my case).

Sowmo0509
  • 54
  • 7
0

It can be JDK version issue try to reinstall it. This steps works for me https://stackoverflow.com/a/67153246/7626614

0

You also might want to check your JAVA_HOME variable, in my case I had set it to a different JDK version and my build was looking for 1.18. when I corrected the path and the build worked.

mmdush
  • 19
  • 8
0

Came across this issue while using Android Gradle Plugin version 8.1.0. Every time I edited something on build.gradle file the error happened.

I checked my project's JDK version, which was at JDK 20.

What helped was to lower JDK Version on my project from JDK 20 to JDK 18.

Tonnie
  • 4,865
  • 3
  • 34
  • 50