Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android studio cannot resolve symbol 'GradleException'

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

like image 447
Roy Hinkley Avatar asked Apr 08 '19 13:04

Roy Hinkley


4 Answers

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

like image 164
amm98d Avatar answered Nov 19 '22 01:11

amm98d


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

  1. just replace to the key GradleException() to FileNotFoundException() like this

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

    into

     throw new FileNotFoundException("could not read version.properties") 
  2. You can also fix this by removing the new keyword before GradleException

    throw  GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") 
like image 41
Paresh Mangukiya Avatar answered Sep 21 '22 13:09

Paresh Mangukiya


This was the solution for me: using

FileNotFoundException()

instead of

GradleException()
like image 23
Lorenzo Tosone Avatar answered Nov 19 '22 00:11

Lorenzo Tosone


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>.

like image 20
Zoe stands with Ukraine Avatar answered Nov 18 '22 23:11

Zoe stands with Ukraine