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

huangapple go评论98阅读模式
英文:

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

问题

我想请教一些关于Android Studio的帮助。这是我第一次处理Android应用程序开发,我对做开发工作没有太多经验。我对这个环境还不太熟悉。尽管如此,我觉得这个活动很有趣,它成为我消磨时间的一个安全空间。

我的问题与代码无关,而是与IDE本身有关。在过去的三天里,我一直被困扰着。我查阅了所有可能与我类似的问题,但没有一个答案对我有帮助。

我创建了一个“Hello World”项目(我还什么都没做),但每次运行它时,我总是遇到这个问题:

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

<details>
<summary>英文:</summary>

I would like to ask some help regarding Android Studio. It is my first time dealing with Android app development and I don&#39;t have much experience with being a developer neither. I&#39;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 &quot;Hello World&quot; project (I haven&#39;t done anything yet), but every time I run it, I always encounter this problem:

```Task :app:preBuild UP-TO-DATE
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 &#39;:app:compileDebugJavaWithJavac&#39;.
&gt; 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 &#39;:app:compileDebugJavaWithJavac&#39;.&lt;129 internal calls&gt;
Caused by: org.gradle.internal.service.ServiceCreationException: Could not create service of type DefaultGeneralCompileCaches using GradleScopeCompileServices.createGeneralCompileCaches().&lt;78 internal calls&gt;
...126 more
Caused by: java.lang.IllegalStateException: Unexpected lock protocol found in lock file. Expected 3, found 0.&lt;20 internal calls&gt;
...203 more

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

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

</details>


# 答案1
**得分**: 4

欢迎来到Android!Android Studio的第一条规则是,如果出现问题,请执行“Build > Clean”。如果这不能帮助,尝试“File > Invalidate Caches / Restart”。这相当于进行了一次清理。

如果这不起作用(可能不起作用,我以前遇到过一次锁定文件的问题),你可以尝试一些方法,虽然不能保证它们会起作用,但也可以试试:

- 运行“Execute Gradle Task”(按下Ctrl+Shift+A然后开始输入),执行“gradle --stop”,然后尝试重新构建。
- 找到“.gradle”数据文件夹(在Windows上是“C:\Users\You\.gradle”),进入“daemon”,找到您正在使用的Gradle版本(在项目中检查“gradle.wrapper.properties”文件)。删除“registry.bin.lock”文件。
- 如果这还不起作用,可以尝试删除“.gradle\caches”文件夹,因为您的错误提到了编译缓存 - 不过需要重新下载一些内容。

我忘记了上次是怎么修复的。[这里有一个讨论串][1],但涉及很多人尝试不同的方法。通常情况下不会出现这些问题,所以你很倒霉,但是有时候确实很麻烦。希望能让你解决问题!

  [1]: https://stackoverflow.com/questions/31743942/errorunexpected-lock-protocol-found-in-lock-file-expected-3-found-0

<details>
<summary>英文:</summary>

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

If that doesn&#39;t work (and it might not, I think I&#39;ve run into it before, the issue with a lock file) there&#39;s a few things you can try, can&#39;t promise they&#39;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&#39;s ``C:\Users\You\.gradle``, go into ``daemon`` and find the version of Gradle you&#39;re using (check the ``gradle.wrapper.properties`` file in your project). Delete the ``registry.bin.lock`` file
 - if that doesn&#39;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&#39;s a thread here][1] but it&#39;s a lot of people trying different things. Generally you don&#39;t get these issues, so you got unlucky, but yeah it can be a pain sometimes. Hope you get it working!


  [1]: https://stackoverflow.com/questions/31743942/errorunexpected-lock-protocol-found-in-lock-file-expected-3-found-0

</details>



# 答案2
**得分**: 2

仅作更新:

我没有找到错误发生的原因,然而,昨天我安装了一条DDR3L内存条(8GB;之前是DDR3 4GB),我的Android Studio上的Java开始正常工作了!

原因可能是处理速度,如果太慢的话它会终止,我猜是这样?我可能对也可能不对,因为当我将语言更改为Kotlin后它就正常工作了。不过我对技术不太了解。

<details>
<summary>英文:</summary>

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&#39;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&#39;m not technologically-savvy.

</details>



huangapple
  • 本文由 发表于 2020年8月21日 06:18:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/63513860.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定