android studio cannot resolve symbol 'GradleException'

时间:2019-04-08 13:55:34

标签: android-studio gradle

Creating new Android Studio project get the following exception in Gradle build file:

Cannot resolve symbol 'GradleException'

enter image description here

Gradle still builds successfully, but still shows this error in editor.

What's missing from my project?

Android Studio 3.3.2

Gradle 4.10.1

compileSdkVersion 27

6 个答案:

答案 0 :(得分:41)

最新的Android SDK不支持GradleException(),请使用FileNotFoundException()

我在此GitHub线程上找到了问题和解决方案:
https://github.com/flutter/flutter/issues/29608

答案 1 :(得分:7)

这是我的解决方案:使用

FileNotFoundException()

代替

GradleException()

答案 2 :(得分:1)

将我的评论移至要求的答案。

AS似乎有各种各样的问题,我不明白为什么会存在,但已通过使缓存无效并重新启动(从文件菜单项)来解决。因为代码可以很好地编译,所以这似乎是其中一种情况,其中高速缓存条目最终以某种方式结束了,我不确定具体发生了什么,但实际上是某种阻止其正常工作的情况。

因此,无论是Gradle还是Java / Kotlin / Scala / <在此处插入语言>,使缓存无效并重新启动都可能会出现这样的问题。

答案 3 :(得分:1)

Android需要更新其文档。对我来说,关键是将GradleException()更改为FileNotFoundException(),所以只需像这样替换您的代码

throw new GradleException("could not read version.properties")

进入

throw new FileNotFoundException("could not read version.properties")

答案 4 :(得分:0)

Android Studio需要更新其默认应用生成器。创建新的Android应用程序时会发生这种情况。

答案 5 :(得分:0)

如果您发现此错误,只需删除“新” 在

throw new GradleException("could not read version.properties")

对于属性中的错误,做同样的事情。