skip to Main Content

I have a small Flutter app and AndroidStudio (Arctic Fox 2020.3.1 Patch 2) is complaining about the following error

in android/app/build.gradle:

Cannot resolve symbol ‘GradleException’

flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.5.1, on macOS 11.6 20G165 darwin-x64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 2020.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2021.2.2)
[✓] Connected device (3 available)

• No issues found!

I tried the suggestions found online so far, like defining the SDK (was already defined, changing it or removing it and setting it again didn’t help).

Occasionally, I also got

  1. in android/app/build.gradle:

Cannot resolve symbol ‘Properties’

  1. in android/settings.gradle:

Cannot resolve symbol ‘File’
Cannot resolve symbol ‘Properties’

edit

Here’s the content of the build.gradle.
It’s more or less the one generated with flutter create

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 30

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }
    
    lintOptions {
        abortOnError false
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "org.myorg.myapp"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//  implementation 'com.google.android.gms:play-services-ads:20.4.0'
}

3

Answers


  1. Your problem can be solved by importing the class GradleException. Just add this code import org.gradle.api.GradleException. If the issue still persists, you may have to reinstall Gradle. You can do this by:-

    1. Invalidate Caches and Restart (Recommended).

    2. In the gradle-wrapper.properties file, in the distribution URL, change the version to the latest supported version, I use 7.1.1

    3. If the problem is with one project only, create a new Flutter project, and place your class files in the new project, as a new build.gradle would be generated, it happens due to corrupted gradle files or bad syncs.

    Login or Signup to reply.
  2. I resolve this problem by setting
    project_structure->module->dependancy->select Module SDK as android latest .
    there was no selection in my project as Module SDK.
    After that
    File->Invalidate Caches->Restart.

    This will help to resolve the problem.

    I had issues in build.gradle file (properties and GradleException).
    Actually we can remove the error by removing the new keyword in front of them. But that is not the real problem and Solution. Do this. Hope you guys it will work.

    Login or Signup to reply.
  3. You can use FileNotFoundException instead of GradleException.

    if (flutterRoot == null) {
        throw new FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search