android studio cannot resolve symbol 'GradleException'
Solution 1
Note: this answer is no longer up-to-date for newer versions of Android Studio and Gradle. See this answer instead.
Android Studio seems to have various problems that I cannot understand why exist, but they're fixed by invalidating the caches and restarting (from the file menu item). Because the code compiles fine, it seems that this is one of those cases, in which a cache entry somehow ends up, I'm not really sure what specifically happens, but essentially something that prevents it from working properly.
So invalidating the caches and restarting may issues like this, whether it's with Gradle or with Java/Kotlin/Scala/<insert language here>.
Solution 2
The latest Android SDK does not support GradleException()
, instead use FileNotFoundException()
.
Or for future readers, maybe use RuntimeException
(if the issue is not file related).
I found the issue and the solution on this GitHub thread:
https://github.com/flutter/flutter/issues/29608
Solution 3
Android needs to update its documentation. This issue is due to not pointing to the correct Android API Platform
Here are some approaches to fix it
-
just replace to the key
GradleException()
toFileNotFoundException()
like thisthrow new GradleException("could not read version.properties")
into
throw new FileNotFoundException("could not read version.properties")
-
You can also fix this by removing the
new
keyword before GradleExceptionthrow GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
Solution 4
This was the solution for me: using
FileNotFoundException()
instead of
GradleException()
Solution 5
if you find this error just remove the "new" in the
throw new GradleException("could not read version.properties")
and for errors in properties, do the same thing.
Roy Hinkley
Updated on July 09, 2022Comments
-
Roy Hinkley almost 2 years
Creating new Android Studio project get the following exception in Gradle build file:
Cannot resolve symbol 'GradleException'
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
-
Zoe stands with Ukraine about 5 yearsInvalidate caches and restart. If that doesn't work, and rebuilding doesn't work either, you'll likely end up having to ignore it. AS seems to complain about a lot of problems that don't exist though, no clue why
-
Roy Hinkley about 5 years@Zoe Many thanks, that fixed! Plz move to answer.
-
Roslan Amir over 3 yearsAndroid Studio needs to update its default app generator. This happens when you create a new Android application.
-
-
Joel Broström over 2 yearsPlease make this the accepted answer since the current one is outdated. @RoyHinkly
-
truthadjustr almost 2 yearsEl magnifeco!!! Another gradle quirk bytes the dust! But what can I say, even Xcode has its own share of hell. Thanks.