Android Studio: Could not create service of type DefaultGeneralCompileCaches using GradleScopeCompileServices.createGeneralCompileCaches()

Viewed 5056

I would like to ask some help regarding Android Studio. It is my first time dealing with Android app development and I don't have much experience with being a developer neither. I'm still new to this environment. Nevertheless, I find this activity fun and it served as a safe space for me to waste my time on.

This problem of mine does not relate to the code but to the IDE itself, and I have been troubled by it for the past three days. I have looked up all the questions that could be similar to mine, but not one answer have helped me.

I made a "Hello World" project (I haven't done anything yet), but every time I run it, I always encounter this problem:

Task :app:preDebugBuild UP-TO-DATE
Task :app:compileDebugAidl NO-SOURCE
Task :app:generateDebugBuildConfig UP-TO-DATE
Task :app:compileDebugRenderscript NO-SOURCE
Task :app:javaPreCompileDebug UP-TO-DATE
Task :app:generateDebugResValues UP-TO-DATE
Task :app:generateDebugResources UP-TO-DATE
Task :app:mergeDebugResources UP-TO-DATE
Task :app:createDebugCompatibleScreenManifests UP-TO-DATE
Task :app:extractDeepLinksDebug UP-TO-DATE
Task :app:processDebugManifest UP-TO-DATE
Task :app:processDebugResources UP-TO-DATE
Task :app:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Could not create service of type DefaultGeneralCompileCaches using GradleScopeCompileServices.createGeneralCompileCaches().

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:compileDebugJavaWithJavac'.<129 internal calls>
Caused by: org.gradle.internal.service.ServiceCreationException: Could not create service of type DefaultGeneralCompileCaches using GradleScopeCompileServices.createGeneralCompileCaches().<78 internal calls>
...126 more
Caused by: java.lang.IllegalStateException: Unexpected lock protocol found in lock file. Expected 3, found 0.<20 internal calls>
...203 more

* Get more help at https://help.gradle.org

BUILD FAILED in 25s
9 actionable tasks: 1 executed, 8 up-to-date
2 Answers

welcome to Android! The first rule of Android Studio is, if things start going wrong, do Build > Clean. If that doesn't help, File > Invalidate Caches / Restart. This does a bit of a spring clean

If that doesn't work (and it might not, I think I've run into it before, the issue with a lock file) there's a few things you can try, can't promise they'll work but hey:

  • run Execute Gradle Task (do ctrl+shift+a and start typing) and do gradle --stop, try rebuilding
  • find the .gradle data folder (on Windows it's C:\Users\You\.gradle, go into daemon and find the version of Gradle you're using (check the gradle.wrapper.properties file in your project). Delete the registry.bin.lock file
  • if that doesn't work, maybe delete the .gradle\caches folder since your error mentions compile caches - stuff will have to redownload though

I forget what I had to do to fix it last time. There's a thread here but it's a lot of people trying different things. Generally you don't get these issues, so you got unlucky, but yeah it can be a pain sometimes. Hope you get it working!

Just to update:

I did not find the reason as to why the error happened, however, yesterday, I have installed a DDR3L RAM (8GB; before it was DDR3 4GB), and my Java on Android Studio has begun working fine!

The reason could be the processing speed, and it just terminated if it's too slow, I guess? I could be wrong or not since it worked fine when I changed the language to Kotlin before. Idk tho. I'm not technologically-savvy.

Related