40
votes

I'm using Gradle to build a java project. When I run any task (assemble, test). I get randomly an error :

Could not create service of type FileHasher using 
GradleUserHomeScopeServices.createCachingFileHasher()

Did any one had the same issue before?

Gradle V:3.5

java 8

I'm using the java plugin.

Thanks,

12
as a workaround, I deleted the lock files. and it worksAnas K
I would suggest marking this answer as the selected oneDouglas Kazumi

12 Answers

49
votes

I was facing the same because I accidentally hit ctrl+z during build, and then the error was the same as yours.

I tried to remove the lock file but it didn't solve the problem.

Then I find all the process related to gradle by ps aux | grep gradle, and then kill -9 <pid> them all. The build backed to normal.

32
votes

In your terminal type this:

./gradlew build

and the outcome would be:

FAILURE: Build failed with an exception.

* What went wrong:
Could not create service of type FileHasher using GradleUserHomeScopeServices.createCachingFileHasher().
> Timeout waiting to lock file hash cache (/Users/zra/.gradle/caches/4.1-rc-1/fileHashes). It is currently in use by another Gradle instance.
  Owner PID: 17571
  Our PID: 26055
  Owner Operation: 
  Our operation: 
  Lock file: /Users/xxx/.gradle/caches/4.1-rc-1/fileHashes/fileHashes.lock

now do:

rm /Users/xxx/.gradle/caches/4.1-rc-1/fileHashes/fileHashes.lock

and build again.

P.S replace xxx with whatever username you've.

15
votes

What worked for me was removing the lock file like suggested in the answer above: rm /Users/xxx/.gradle/caches/4.1-rc-1/fileHashes/fileHashes.lock and also killing the IDLE processes by running the command

./gradlew --status

It generates a list of gradle processes with status like

  PID STATUS   INFO
 23580 IDLE     5.2.1
 23860 IDLE     5.2.1
 19058 STOPPED  (stop command received)

Then kill one of the idle processes by kill <PID> and run the gradle build again.

8
votes

One simple cause is that gradle daemon is not started with the same environment variable. I had the same issue while changing the gradle user home.

Simply stop the daemon:

gradle --stop
4
votes

change the ownership of .gradle/ using the following command:

sudo chown -R <USERNAME> .gradle/ 
1
votes

I couldn't find this info elsewhere, posting in case it helps someone:

I had the same issue while running Android Studio on ChromeOS (on Chromebook).

I had shared a Google Drive folder with Linux (by selecting a folder, right-clicking and selecting Share with Linux) and created my project there. Build failed with this error, and removing the lock file did nothing for me.

Problem was resolved for me by re-creating the project under a 'Linux folder'.

0
votes

If the OS is Windows. Try this: gradlew build Find de PID Process

enter image description here

And in CMD execute this command

TASKKILL /F /PID  #PID
-1
votes

This was same problem for me before some days and now only it's your or the user reading this solution.

  1. Uninstall full android studio (means- 'after uninstall from control panel, delete folders of Android Studio,') folders to be deleted:

    C:\Program Files -> Android, C:\Users{user folder name} -> .android & .gradle & {other folders related to Android Studio}

  2. Reinstall form it's .exe and make sure your PC in connected with internet and with proper speed.

  3. Download all SDK files as mention in that and keep downloading in Android Studio only. [do not download form other source- otherwise it will show errors, be careful]

  4. Click on new project and select empty project and give the name and click on finish.

you will redirect to another window and than the main thing starts that is installation of GRADLE so for this you should have high connectivity of internet and that it will download automatically and and and now your are ready to go.

-1
votes

I had the same issue and the solution was to login with the correct user and then run gradle. I was logged in with a user that didn't had rights to run the tasks.

-1
votes
  • I just moved a project from Download folder (on Mac) to another one
  • If you try to build an inner project - try to go to root project and call
./gradlew <moduleName>:<command>
-1
votes

The easiest solution in my case wast to run

In case of linux

sudo ./gradlew bundleRelease

if windows then login with the user who has highest privileges.

Because this error occurred due to insufficient permissions

-1
votes

In my case, I was keeping the entire project in a folder managed by Google Drive Stream. Since that's a very rudimentary filesystem, Android Studio or Gradle (I can't tell which) was trying to do something on the FS that Google Drive Stream doesn't allow.

I simply moved the project onto my local drive and that fixed it!