My project works and builds successfully on my Mac but I cloned from github and although Android Studio appears to work normally, the project wouldn't build. I setup this project using Kotlin DSL.

Gradle sync failed: could not find extension implementation class org.jetbrains.kotlin.idea.scripting.gradle.roots.GradleBuildRoot

Tried invalidate cache, removed all .gitignore rules but it's still the same. Any ideas?

推荐答案

我也有同样的问题(注意:运行Linux/Ubuntu 20.04 LTS和Android Studio 4.1.1).

Things I tried that did NOT work and error persisted :

  • Invalidate Caches / Restart
  • 重启
  • .gradle.m2文件夹进行核爆
  • Android Studio re-install
  • 将kotlin gradle插件从1.4.21降级到1.4.10

What did work :

  • Moving the project to a different folder/location on disk and open Android Studio

As soon as I moved the project back to the original location I would start getting the same error. This lead me to believe it was some sort of caching issue, separate from the caches "invalidated".

Solution :

Android Studio / Intellij creates a hidden folder called :

On Linux :

AS : ~/.cache/Google/AndroidStudioX.X

IJ:~/.cache/Jetbrains/IntelliJIdea2020.X

On Mac :

AS:~/Library/Caches/Google/AndroidStudioX.X

IJ : ~/Library/Caches/Jetbrains/IntelliJIdea2020.X

在Windows上:

AS : %HOME%\AppData\Local\Google\AndroidStudioX.X

IJ : %HOME%\AppData\Local\Jetbrains\IntelliJIdea2020.X

Inside this folder are other various folders, however I removed the relevant workspace file (workspace/[project name].[hashed value].xml) after which problem went away when opening the project again, from its original location.

因此,"使缓存失效/重新启动"似乎不会使所有缓存失效!

I hope this resolves you problem!

Update

As this answer has had quite a few upvotes it would appear that this might be a ongoing bug with Intellij. If anyone has this problem, before resolving with the suggested solution consider checking there isn't an open issue on the bug tracker and submitting a new issue : https://youtrack.jetbrains.com/issues

Feel free to edit this update with issue if one is opened.

Update 2

Issue opened by @GeniusRUS :

https://youtrack.jetbrains.com/issue/KT-44937

Kotlin相关问答推荐

UByte范围. Min_UTE.. UByte.MAX_UTE不符合预期

调用即发即忘方法--哪个作用域?

房间数据库操作中的协程取消

Kotlin 复制列表中的项目以创建具有相同数据的不同对象的新列表

在 Kotlin 中将两个字节转换为 UIn16

ActivityResultContracts TakePicture 结果总是返回 false

将 SharedPreferences 中的值公开为流

SpringBoot 2.5.0 对于 Jackson Kotlin 类的支持,请在类路径中添加com.fasterxml.jackson.module: jackson-module-kotlin

如何禁用智能投射突出显示 Kotlin?

如何在 Kotlin 中判断数组类型(不是泛型类型)

Hilt Activity 必须附加到 @AndroidEntryPoint 应用程序

更新到版本4.10.1/4.10.2后 Gradle 同步失败

如何在 Kotlin 中传递有界通配符类型参数?

Jacoco在Gradle 7.0.2和Kotlin 1.5.10上失败

如何将 Kotlin 日期中的字符串或时间戳格式化为指定的首选格式?

修改扩展函数中的this

Kotlin协程无法处理异常

如果kotlin已经有了getter和setter,为什么在数据类中有componentN函数?

kotlin中的全局可拓函数

Kotlin反射不可用