First Flutter App error: cannot resolve symbol "Properties"

Intellij IdeaFlutter

Intellij Idea Problem Overview


I followed the steps in the Flutter document and tried to build my first Flutter app in Intellij IDEA. And when I try to run it,there was an error about my JAVA_HOME variable. And an error about cannot resolve symbol "Properties" in the build.gradle file. I really don't know what to do.

This is my error information displayed in the Console window.

Launching lib\main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Finished with error: ProcessException: Process 
"F:\untitled\android\gradlew.bat" exited abnormally:

ERROR: JAVA_HOME is set to an invalid directory: F:\Google download\jdk- 
10.0.1_windows-x64_bin.exe

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
  Command: F:\untitled\android\gradlew.bat -v

Actually there is nothing wrong with my JAVA_HOME variable, I set it to the proper directory: C:\Program Files (x86)\Java\jdk1.8.0_131.

And I run the command it shows above "F:\untitled\android\gradlew.bat -v", it seemed to update the gradle version, but the error didn't resolved.

And this is the code in build.gradle file.

def localProperties = new Properties() 
//there will be a highlight on Properties indicates that 'cannot resolve symbol "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.")
//the same as the Properties on GradleException
}

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 from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.untitled"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    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 {
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

Intellij Idea Solutions


Solution 1 - Intellij Idea

> This issue is due to not pointing to correct Android API Platform

Solution :

In the Android Studio File > Project Structure

  1. Now a window pops up
  2. Within that select Project Settings/Project
  3. Make sure Project SDK is set to latest platform as mentioned in the pic below

enter image description here

  1. Next select Project Settings/Modules sub tab
  2. There select the lastest Android SDK as you did in step-3

enter image description here

  1. Finally replace the GradleException() with FileNotFoundException() as mentioned below

enter image description here

Solution 2 - Intellij Idea

I tried all other suggestions, and they did not help. Then I have removed "new" in front of GradleException, and it solved the problem:

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

It worked perfectly fine with the "new" word for a long time. I don't know what have caused this change.

Solution 3 - Intellij Idea

I've just had this issue and in my case was due to an invalid SDK configuration. I've solved by going to:

> Project structure > Project Settings > Modules > Module SDK

and switching from <no project SDk>

to Android api 29 platform

Solution 4 - Intellij Idea

Go to File -> Project Structure -> Modules -> Select your project -> apply your API

enter image description here

Solution 5 - Intellij Idea

For me just deleting new before Properties and GradleException it have solved it.

• Flutter version 1.21.0-10.0.pre.55 | Master Channel |
• Dart version 2.10.0 (build 2.10.0-11.0.dev)
• Android Studio 4.0.1

here is first lines in build.gradle 'contains changes'

def localProperties = 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 GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

. . . . . . . .

Solution 6 - Intellij Idea

Need to include google maven repository to your project level build.gradle file.

buildscript {
    repositories {
        google()
        jcenter()
        maven {                                    //add this section 
            url "https://maven.google.com"           
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
    }
}

Solution 7 - Intellij Idea

> Cannot resolve symbol 'Properties'
Cannot resolve symbol > 'GradleException'

or even in the case of many errors on opening manifest file.

It's not an issue, you don't need to do anything. These are shown because IDE didn't detect them in the normal mode. Just 'Open for Editing in Android Studio' (you may find it on TOP-RIGHT) then Select 'New Window', you will find everything well.

Solution 8 - Intellij Idea

It's working for me:

  1. File > Project Structure (Command + ;) > Under Project Settings/Project > Set Project SDK to Android API 29 Platform
  2. There should be a notification stating there is an invalid item in the dependencies list under Project Structure/Problems. If there is, go to Project Structure > Under Project Settings/Modules > select app_name_android > Dependencies tab > choose the latest "Android API 29 Platform" in the Module SDK box.
  3. Update GradleException() to FileNotFoundException() under android/app/build_gradle since it's not supported in the Java version of Android API 29 Solution found

Solution 9 - Intellij Idea

Yes, i follow this https://github.com/flutter/flutter/issues/37391#issuecomment-544823712 and i change GraddleException to FileNotFoundException in android/app/build.gradle. Otherwise upgrade kotlin version in android/build.gradle to 1.3.50. At least, upgrade gradle distributionUrl to version 5.4.1

Solution 10 - Intellij Idea

I have same problem. I get this error because I edit android module without open it first using AS in another tab (Tools -> Flutter -> Open Android module..). Then I have a solution, just restart and kill the chache in your Android Studio (File -> Invalidate Chache / Restart).

It fixed for me, I hope you too

https://github.com/flutter/flutter/issues/29608#issuecomment-528243662

Solution 11 - Intellij Idea

It's not an error, don't remove new keywords from GradleException and properties() method just restart your android studio your problem will be solved.

Solution 12 - Intellij Idea

It worked for me(android studio version: 4.1, flutter version: 2.5)

  1. Open pubspec.yaml -> run "pub get", now
  2. Go to File -> Invalidate Chache / Restart

Solution 13 - Intellij Idea

I had the same issue in Android Studio. It looks like a bug with the Flutter Plugin so it's pretty likely it's a problem in Intellij too. In Android Studio there is a link to "Open for Editing in Android Studio" (top right). When I click that I see there are no longer any issues highlighted. I would check for a similar link in IntelliJ. Here is the Flutter issue where I learned of this: https://github.com/flutter/flutter/issues/37391.

Solution 14 - Intellij Idea

In yours "project\android\build.gradle" Just change:

classpath 'com.google.gms:google-services:4.3.2'

to:

classpath 'com.google.gms:google-services:4.0.2'

Solution 15 - Intellij Idea

According to flutter documentation https://flutter.dev/docs/development/tools/android-studio#android-ide

Opening the root directory of a Flutter project doesn’t expose all the Android files to the IDE. Flutter apps contain a subdirectory named android. If you open this subdirectory as its own separate project in Android Studio, the IDE will be able to fully support editing and refactoring all Android files (like Gradle scripts).

Solution 16 - Intellij Idea

Update: Oct. 15, 2020.

I am running Flutter Version 1.12.13+hotfix9 in Android Studio Version 4.1 (re-installed today) with runtime version 1.8.0_242-release-1644.... on Windows 10, amd64.

I repaired both the project level and app level gradle build files by removing the word 'new' before 'Properties' and 'GradleException' and in both files the Studio error messages were removed.

Solution 17 - Intellij Idea

For me, it's because of invalid file

> pubspec.yaml

Please re-check the file configurations.

Solution 18 - Intellij Idea

First of all click on file section then file

after in that we have project structure section click on the project structure after that go to project in that and change the project sdk to latest if its null or its outdated , as I have updated mine to 30

project sdk to change here change the sdk if necessary and apply the changes after that go to problems which is beneath project if it shows some error just fix it with a tap as you can see minefix it after that go to app/build.gradle then change the GradleException to FileNOtFoundExcetion Now you are good to go after saving all errors will be vanishFileNotFoundException changes

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionWellenView Question on Stackoverflow
Solution 1 - Intellij IdeaShriram NavaratnalingamView Answer on Stackoverflow
Solution 2 - Intellij IdeaAndrei VolginView Answer on Stackoverflow
Solution 3 - Intellij IdeadaveoncodeView Answer on Stackoverflow
Solution 4 - Intellij IdeaRichard RexView Answer on Stackoverflow
Solution 5 - Intellij IdeamohannadalnonoView Answer on Stackoverflow
Solution 6 - Intellij IdeaTrendyView Answer on Stackoverflow
Solution 7 - Intellij IdeaPankaj KumarView Answer on Stackoverflow
Solution 8 - Intellij IdeaaslamconsoleView Answer on Stackoverflow
Solution 9 - Intellij IdeaTeguh SyahputraView Answer on Stackoverflow
Solution 10 - Intellij IdeaYusin KimView Answer on Stackoverflow
Solution 11 - Intellij IdeaHamid ShahView Answer on Stackoverflow
Solution 12 - Intellij IdeaPRANAV SINGHView Answer on Stackoverflow
Solution 13 - Intellij IdearkunboxedView Answer on Stackoverflow
Solution 14 - Intellij IdeaThiago TellesView Answer on Stackoverflow
Solution 15 - Intellij IdeaIvan MaymeskulView Answer on Stackoverflow
Solution 16 - Intellij IdeaIanView Answer on Stackoverflow
Solution 17 - Intellij IdeaJohanView Answer on Stackoverflow
Solution 18 - Intellij Ideasaivignesh adepuView Answer on Stackoverflow