Gradle :Could not create service of type FileHasher

a 夏天 提交于 2020-05-07 11:52:26

问题


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,


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


This worked for me:

  1. Turned off antivirus file protection

  2. Invalidate caches/Restart

  3. Run app




回答5:


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

And in CMD execute this command

TASKKILL /F /PID  #PID



回答6:


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




回答7:


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.



来源:https://stackoverflow.com/questions/45177977/gradle-could-not-create-service-of-type-filehasher

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!