10

Can someone please explain to me what this error is and how to resolve this error?

Gradle sync failed: D:\SoundsandPictures.gradle\4.4\fileHashes\fileHashes.lock (Access is denied)

Note: My project was on D: drive and i accidently deleted all my data on the drive and recovered it using a recovery software and getting this error while opening the project in android studio.

danish
  • 177
  • 1
  • 1
  • 14

11 Answers11

23

Goto File -> Invalidate caches / Restart

Shutdown Android Studio

Rename/remove .gradle folder in the user home directory

Restart Android Studio (It will download gradle metadata and data)

Gradle build succeed

Rebuild project. Done.

EDIT

Try this for Mac OS

Go to SDK manager (with Administrator rights), scroll down till the end, download "Android Support Library".

And it works (don't forget Administrator rights).

Reference this SO Question..

amit
  • 681
  • 5
  • 17
  • It's not working bro and what do you mean by all project files. – danish Jun 22 '18 at 17:32
  • Now where are the files stored after recovery – amit Jun 22 '18 at 17:53
  • I stored all the files in a seperate folder in the other drive and just copy and pasted the project in D: – danish Jun 22 '18 at 17:56
  • The problem here is administrator permission, i don't know why but this time in d: drive it is asking for administrator permission every time when i copy paste or delete something. So i thing this issue is different and all solutions provided by you are correct. Now i am using my project in the E drive and it's not giving that access denied error but because of recovery software some of my java file text got converted into special symbols like this '肙ⱉ鳪⽛芨̆ഋ垦' – danish Jun 25 '18 at 09:28
  • gr8 it worked.. thata the reason i asked to ensure that all your project files were recovered during recovery.... – amit Jun 25 '18 at 09:46
  • What about MacOs. I have the same problem, what gradle folder should i remove? – Pablo Rodriguez Apr 10 '19 at 17:55
  • Do you care to explain why it fixes it? It is like demolishing and re-building a house to repair its window! – AaA Mar 25 '21 at 01:52
5

If do you have an antivirus software, try to check if it has blocked Android Studio.

BitDefender did block my AndroidStudio

Samuel Liew
  • 72,637
  • 105
  • 156
  • 238
1

In my case, I hid the .gradle file. On unhiding the file, it was fine.

Reeshabh Ranjan
  • 224
  • 2
  • 11
1

Very late answer, but I was getting the error "caches\5.1.1\file-changes\last-build.bin (Access is denied)", deleting that file and re-building the project worked for me.

1

/.gradle/4.6/fileChanges/last-build.bin%20(Access%20is%20denied)

I resolved this issue by deleting .gradle folder and then restart android studio clean and rebuild

Awa93
  • 21
  • 3
0

i deleted the file, then appear another message but with other file, i did the same 3 times, and then a clean and rebuild and worked. PS: those files regenerate after the build, so no problem there.

karique
  • 516
  • 6
  • 16
0

Same error was showing while doing in vs code. I solved just by deleting this .gradle\caches\6.1.1\file-changes\last-build.bin file. After relaunching the vscode the problem wa

0

make files not hidden (unchiek hidden in windows)

-1

OK.. To solve this issue, simple navigate to your project folder like C:\Users\AndroidStudioProjects\Project.gradle\taskArtifacts folder and delete the file. The fileHashes.lock is holding a global lock and is preventing you from running your script. Deleting the folder would create the file again and your project will get built. Also there is a possibility that there are other locked files. Simply delete everything within the C:\Users\Administrator.gradle\caches folder.

amit
  • 681
  • 5
  • 17
  • Not working , i have tried it and now it is saying failed to create directory 'D:\soundsandpictures\.gradle\4.4\fileHashes – danish Jun 23 '18 at 05:52
  • I also want to add one more thing here is when i start the android studio it starts with a popup 'Failed to save setting. please restart android studio.' – danish Jun 23 '18 at 05:59
  • after following the above procedure do this once again... Goto File -> Invalidate caches / Restart Shutdown Android Studio .. then do Build->Clean Project and also Build Project.. to create the deleted file once again.. – amit Jun 23 '18 at 06:15
-1

Create a new Android project and move all your recovered files into it. This issue you are facing is because of existing settings in the old project.

Then ...

Go to File--> Project Structure --> Check Use Embedded JDK (Recommended)Check Use Embedded JDK

amit
  • 681
  • 5
  • 17
-1

whenever this happens JUST DEL (MAKE A BACKUP 1ST) THE CULPRIT FILE (THE FILE RIGHT BEFORE THE MSG "ACCESS IS DENIED"

hope this helps