Gradle :Could not create service of type FileHasher

Viewed 59950

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,

13 Answers

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.

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.

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

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

sudo chown -R <USERNAME> .gradle/ 

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'.

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

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 Git 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!

I got the same error when I tried to execute ./gradlew from WSL2 ubuntu. As suggested by @user16115, I stopped the running gradle in my host machine (windows machine) by issuing command gradlew.bat --stop.

After stopping the gradle in my host machine, I issued the same command ./gradlew in WSL2, gradle worked as expected.

ps: I have mounted my C:/ drive into WSL2 ubuntu.

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.

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.

  • 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>

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

Related