Asim Javaid
Asim Javaid

Reputation: 577

What is causing "cannot resolve symbol GradleException" in a Flutter project?

I have created a Flutter project in Android Studio. The project was working fine until I opened the app-level Gradle file as when I open is starts showing two errors: 1) 'Cannot resolve symbol Properties' and 2) 'cannot resolve symbol GradleException'

I click on "Open for editing in Android studio" and the error 1) disappeared, but 'cannot resolve symbol GradleException' is still there. I have the latest Gradle and Android Studio. The project was working fine until I opened this app-level Gradle file.

As shown

Upvotes: 50

Views: 52737

Answers (8)

mkiziltay
mkiziltay

Reputation: 63

Sometimes the IDE can attack itself. To do this, change the folder named android (in the project location path) to OLDandroid.

Then, re-set your project as an android project via the IDE. (For VS Code: there is the phrase "set as android project" right under the emulator selection menu).

The IDE will create a new android folder for you at this stage. You can then move the necessary code blocks from the OLDandroid folder into the new android folder (manifests.xml, res, build properties, release keys etc.) and run the project.

If you are done with the OLDandroid folder, you can delete it.

Upvotes: 0

warren zingwena
warren zingwena

Reputation: 857

You need to upgrade your SDK's version to the latest ones in your build.gradle at the app level.

Upvotes: -2

Hanna Najih
Hanna Najih

Reputation: 11

I removed the 'new' keyword, and everything is worked. Don't forget to keep your IDE up-to-date all the time.

Enter image description here

Upvotes: -1

Coldstar
Coldstar

Reputation: 1341

It sounds like an IDE issue. Restart Android Studio, but going to menu FileInvalidate Caches / Restart. This happens to me when I synchronise Gradle after updates sometimes

Upvotes: 6

Prati V
Prati V

Reputation: 635

Use:

throw GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")

I tried by removing the "new" keyword and it somehow worked for me.

I changed

throw new GradleException

to

throw GradleException.

Upvotes: 53

warren zingwena
warren zingwena

Reputation: 857

Set Project SDK to Android API Platform version 29 (or the latest version, 30), like so:

defaultConfig {
    ...
    minSdkVersion 16
    targetSdkVersion 30
}

And update GradleException() to FileNotFoundException().

Please follow this: Have a problem on Cannot resolve symbol for properties and Gradle exception #29608

This works for me.

Upvotes: 76

John Fort
John Fort

Reputation: 1

Removing the build folder worked for me.

Upvotes: 0

Walied Abdulaziem
Walied Abdulaziem

Reputation: 399

  1. Open build.gradle file and set targetSdkVersion and compileSdkVersion to 29

  2. Click on File => Project Structure => Project then set Project SDK to Android API 29 platform

  3. In project structure => Module and select dependencies in the right column and then set Module SDK to Android API 29 platform

  4. Now open build.gradle and replace GradleException with FileNotFoundException

Upvotes: 11

Related Questions