Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have a problem on Cannot resolve symbol for properties and Gradle exception #29608

Closed
GurusankarS opened this issue Mar 19, 2019 · 57 comments
Closed
Labels
t: gradle "flutter build" and "flutter run" on Android tool Affects the "flutter" command-line tool. See also t: labels.

Comments

@GurusankarS
Copy link

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) {
throw new GradleException("versionCode not found. Define flutter.versionCode in the local.properties file.")
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
throw new GradleException("versionName not found. Define flutter.versionName in the local.properties file.")
}

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

android {
    compileSdkVersion 27

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.thinkdigitalrepair.livekhflutter"
        minSdkVersion 16
        targetSdkVersion 27
        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'
}
@jonahwilliams jonahwilliams added tool Affects the "flutter" command-line tool. See also t: labels. t: gradle "flutter build" and "flutter run" on Android labels Mar 19, 2019
@atereshkov
Copy link

Same for me here. Have anyone managed to resolve it?

@aliaazakii
Copy link

what is the solution please ?

@aliaazakii
Copy link

Same for me here. Have anyone managed to resolve it?

did u know the solution?

@atereshkov
Copy link

did u know the solution?

If I recall correctly, I had a problem after switching to the new MacBook. So I've fixed it creating all the keystore things one more time. I mean signing configs, kjs, etc.
But this is how I remember it, it's been a while. I can dig into it if you really need to.

@sumaya99
Copy link

sumaya99 commented Aug 4, 2019

plz what's the solution , i tried many ways nothing work :( , plz help , if u have fixed ur own

@kunaldas1997
Copy link

Facing the same. Solution please :/

@NgYewChun
Copy link

NgYewChun commented Sep 4, 2019

facing same problem, anyone has solution please?
this happened after I move project to new laptop and android sdk is installed in a different folder.

@rrifafauzikomara
Copy link

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

@kunaldas1997
Copy link

Ok. Found the solution.

Gradle shows the error because Flutter is not implemented with Gradle. That Means Gradle isn't build for Flutter, but for Java/Kotlin only.

If you use VS Code, you will see no error is there.

So, just build and don't mind gradle, other than adding stuffs as mentioned by Flutter team.

@Richard2926
Copy link

Richard2926 commented Sep 18, 2019

(The following API 28 can be replaced with 29 as well since it is the latest as of now. 28 is recommended)

Change your target SDK and compile SDK version to 28

Install API 28 from File -> Settings -> Appearance and Behaviour -> System Settings -> Android SDK -> SDK tools -> Select "Show package details from bottom right. Select all 28 versions, Apply.

Go to File -> Project Structure -> SDK's under Platform Settings -> Define Android API 28 as build target and enter the path for the SDK "C:\Users%USERNAME%\AppData\Local\Android\Sdk", Apply

Now, Go to modules under project settings in the same project structure, select Android API 28 from the dropdown. Restart the App.

Hope this helps

@prateekkr1
Copy link

(The following API 28 can be replaced with 29 as well since it is the latest as of now. 28 is recommended)

Change your target SDK and compile SDK version to 28

Install API 28 from File -> Settings -> Appearance and Behaviour -> System Settings -> Android SDK -> SDK tools -> Select "Show package details from bottom right. Select all 28 versions, Apply.

Go to File -> Project Structure -> SDK's under Platform Settings -> Define Android API 28 as build target and enter the path for the SDK "C:\Users%USERNAME%\AppData\Local\Android\Sdk", Apply

Now, Go to modules under project settings in the same project structure, select Android API 28 from the dropdown. Restart the App.

Hope this helps

Still not resolved!!

@workerbee22
Copy link

Same issue AS 3.5.1 ... Gradle plugin 3.5.1.

@LOG-TAG
Copy link

LOG-TAG commented Oct 5, 2019

same problem :(

@Thiagoag
Copy link

Same problem here. Does anyone has a solution or a workaround?

@febs
Copy link

febs commented Oct 11, 2019

Here also the default build.gradle file created by flutter when generating a project gives that annoying error.

Environment:

Android Studio 3.5.1 on Linux
Flutter 1.9.1+hotfix.4 ( channel stable )
Flutter plugin v40.1.2

There shouldn't be any warnings or errors out of the box, that's confusing to beginners.
Thanks,

@paavithra
Copy link

Facing the same problem. When using firebase, I am not able to sync after making changes in the gradle file so not able to proceed..

@techwn
Copy link

techwn commented Oct 25, 2019

Here also the default build.gradle file created by flutter when generating a project gives that annoying error.

Environment:

Android Studio 3.5.1 on Linux
Flutter 1.9.1+hotfix.4 ( channel stable )
Flutter plugin v40.1.2

There shouldn't be any warnings or errors out of the box, that's confusing to beginners.
Thanks,

Agree! I've solved all the problems in the project structure, but it doesn't work.

@TianleiSun
Copy link

same problem here

@iojason
Copy link

iojason commented Nov 1, 2019

Able to solve this after 4 hours of diving. I ran into this issue after updating to macOS Catalina. Properties() and GradleException() are causing problems because the Android API library is not linked when you open it in Flutter. If you look under External Libraries, you should notice "< Android API 2X Platform >" is missing. If it is, take the following steps to fix this issue:

1. File > Project Structure (Command + ;) > Under Project Settings/Project > Set Project SDK to Android API 29 Platform
jasondphan-flutter-project-sdk-not-set
jasondphan-flutter-project-sdk-set

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.
jasondphan-flutter-android-api-library-problem
jasondphan-flutter-invalid-android-api-module-dependency
jasondphan-flutter-android-api-module-dependency-updated

3. Update GradleException() to FileNotFoundException() under android/app/build_gradle since it's not supported in the Java version of Android API 29

That's it! You should notice the Android API 29 Platform is now visible under External Libraries.
jasondphan-flutter-properties-gradle-exception-solved

@timeshift-ted
Copy link

Flutter needs to update their documentation. The key for me was changing GradleException() to FileNotFoundException(). Thank you @jasondphan

@daniele777
Copy link

Guys need help i'm coding new app with flutter but i'll try to implement from this guide https://fireship.io/lessons/flutter-realtime-geolocation-firebase/
but i have same problem on gradle

`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 FileNotFoundException("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 29

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

lintOptions {
    disable 'InvalidPackage'
}

defaultConfig {
    // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
    applicationId "com.example.csf_2020"
    minSdkVersion 21
    targetSdkVersion 29
    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 {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
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'
}
apply plugin: 'com.google.gms.google-services' `

Properties() say can't resolve

and GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") can't resolve

when i compile gradle

Finished with error: Gradle task assembleDebug failed with exit code 1

htaiwan pushed a commit to htaiwan/Flutter_Bootcamp that referenced this issue Nov 8, 2019
@ghost
Copy link

ghost commented Nov 25, 2019

Able to solve this after 4 hours of diving. I ran into this issue after updating to macOS Catalina. Properties() and GradleException() are causing problems because the Android API library is not linked when you open it in Flutter. If you look under External Libraries, you should notice "< Android API 2X Platform >" is missing. If it is, take the following steps to fix this issue:

1. File > Project Structure (Command + ;) > Under Project Settings/Project > Set Project SDK to Android API 29 Platform
jasondphan-flutter-project-sdk-not-set
jasondphan-flutter-project-sdk-set

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.
jasondphan-flutter-android-api-library-problem
jasondphan-flutter-invalid-android-api-module-dependency
jasondphan-flutter-android-api-module-dependency-updated

3. Update GradleException() to FileNotFoundException() under android/app/build_gradle since it's not supported in the Java version of Android API 29

That's it! You should notice the Android API 29 Platform is now visible under External Libraries.
jasondphan-flutter-properties-gradle-exception-solved

Thank you so much for this!!

@timsneath
Copy link
Contributor

Closing this issue for now since the original question seems to have been answered, and the issue is now degrading into a variety Gradle-related troubleshooting issues.

If you are still experiencing the original issue, you're welcome to reopen it. Please tell us exactly how to reproduce the problem you're running into. Attach a small sample that demonstrates the issue, or include the specific tool commands that reproduce the problem along with the results of running flutter doctor -v.

For more general troubleshooting, good places to ask questions or work through problems where you're more likely to get a fast response include:

Thanks for using Flutter!

@AbhijeetBharti
Copy link

The key for me was changing GradleException() to FileNotFoundException(). Thank you @jasondphan

@alberduris
Copy link

alberduris commented Jan 10, 2020

Closing this issue for now since the original question seems to have been answered, and the issue is now degrading into a variety Gradle-related troubleshooting issues.

If you are still experiencing the original issue, you're welcome to reopen it. Please tell us exactly how to reproduce the problem you're running into. Attach a small sample that demonstrates the issue, or include the specific tool commands that reproduce the problem along with the results of running flutter doctor -v.

For more general troubleshooting, good places to ask questions or work through problems where you're more likely to get a fast response include:

Thanks for using Flutter!

Changing the default GradleException() for FileNotFoundException() does not seems like a solution to me. More like a workaround or hackiss way to bypass it honestly. @timsneath

@sewah2012
Copy link

I had the same problem ... but Solved it:

i simply open the gradle file by righ clicking on it chose the option flutter and open for editing in andriod studio.. once open i clicked around a few times without changing anythin and boom all errors wer gone... Hope this work for you too ... good luck and happy coding :)

@aishoo1612
Copy link

Facing the same problem. When using firebase, I am not able to sync after making changes in the gradle file so not able to proceed..

Same Issue, I mean it shows no error and when I open to sync with firebase it throws i this error

@aishoo1612
Copy link

Able to solve this after 4 hours of diving. I ran into this issue after updating to macOS Catalina. Properties() and GradleException() are causing problems because the Android API library is not linked when you open it in Flutter. If you look under External Libraries, you should notice "< Android API 2X Platform >" is missing. If it is, take the following steps to fix this issue:
1. File > Project Structure (Command + ;) > Under Project Settings/Project > Set Project SDK to Android API 29 Platform
jasondphan-flutter-project-sdk-not-set
jasondphan-flutter-project-sdk-set
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.
jasondphan-flutter-android-api-library-problem
jasondphan-flutter-invalid-android-api-module-dependency
jasondphan-flutter-android-api-module-dependency-updated
3. Update GradleException() to FileNotFoundException() under android/app/build_gradle since it's not supported in the Java version of Android API 29
That's it! You should notice the Android API 29 Platform is now visible under External Libraries.
jasondphan-flutter-properties-gradle-exception-solved

Follow the one above and if it still doesn't works then change the following Step by Step and run the app at each step.

Step 1 - In (\build.gradle) change
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")

to

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

Step 2 - Run flutter doctor -v in terminal and give permission to all if any of them are missing.

Step 3 - In (\build.gradle) add this in dependencies

`dependencies {

    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

    classpath 'com.android.tools.build:gradle:3.2.1'

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

}

}`

Finally go to File-> Invalidate Caches/ Restart and your app should work fine now.

Thank you so much, it worked! I was sweating because of this error. Thanks Again

@salaheddinelhamraoui
Copy link

Able to solve this after 4 hours of diving. I ran into this issue after updating to macOS Catalina. Properties() and GradleException() are causing problems because the Android API library is not linked when you open it in Flutter. If you look under External Libraries, you should notice "< Android API 2X Platform >" is missing. If it is, take the following steps to fix this issue:
1. File > Project Structure (Command + ;) > Under Project Settings/Project > Set Project SDK to Android API 29 Platform
jasondphan-flutter-project-sdk-not-set
jasondphan-flutter-project-sdk-set
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.
jasondphan-flutter-android-api-library-problem
jasondphan-flutter-invalid-android-api-module-dependency
jasondphan-flutter-android-api-module-dependency-updated
3. Update GradleException() to FileNotFoundException() under android/app/build_gradle since it's not supported in the Java version of Android API 29
That's it! You should notice the Android API 29 Platform is now visible under External Libraries.
jasondphan-flutter-properties-gradle-exception-solved

Thank you so much for this!!

The first step was Enough to solve the problem

@rajdaksh
Copy link

FileNotFoundException
Thank you @jasondphan

@yvonmanzi
Copy link

@zyllus17 Thanks for putting your solution out here! It worked for me as well.

@GeekOnHeels01
Copy link

FileNotFoundException()

Your response is apt and resourceful.

Thank you

@developer-ed
Copy link

@zyllus17 Thanks for clear resolution steps it addressed it cleanly.

@ibrahimEltayfe
Copy link

change GradleException to FileNotFoundException

@ahmedwahab99
Copy link

Acceptable, simpler SOLUTION that worked for me........

Haven't checked all the comments and am not sure if anyone has provided this solution, but if u SIMPLY checked your SDK manager you'll probably find that your API 29 states is showing that it needs to be updated.. so just click on it and you'll find an updating icon on the left, once its there press "Apply" button

@Mohanad-ALNUNU
Copy link

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.")
    }
    
.
.
.
.
.
.
.
.






Psycl0n3 added a commit to Psycl0n3/Osseus-Fracture-Detection-App that referenced this issue Aug 29, 2020
… be found through following the advice in the following webpage: flutter/flutter#29608 (comment)

Also updated some of the dependencies to the most recent versions
@fletgo
Copy link

fletgo commented Sep 20, 2020

this video helps

https://www.youtube.com/watch?v=NJp14BeTjAs

@boloni225
Copy link

Flutter needs to update their documentation. The key for me was changing GradleException() to FileNotFoundException(). Thank you @jasondphan

This worked for me, thanks 👍

@xster
Copy link
Member

xster commented Sep 28, 2020

We're not actively monitoring closed issues. If there are still unresolved issues, please open a new GitHub issue (https://github.com/flutter/flutter/issues/new/choose) and describe the the reproduction steps and the expected outcome.

Reading through this thread, I'm not entirely sure what the original question is. Based on the responses, I'm guessing it's perhaps related to co-editing Android code in the /android/ directory while having a Flutter project root open in Android Studio with the Flutter IDE plugin? But I might be wrong. Please describe the needed workflow in a new issue.

@furkankaracan
Copy link

Deleting the new resolved the issue for me

@vintx64
Copy link

vintx64 commented Jan 19, 2021

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

thx bro it works

@Ruukas97
Copy link

It might be more of a workaround than a solution, but I was looking for a way to ignore the error. I found that you can right click build.gradle and select Mark as Plain Text. Then it will not be checked for errors. You can always mark is as groovy again.

@CorneluisTech789
Copy link

Hi there guys the fix is easy just go to app/build.gradle and in line 11 just remove the new

throw GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") if u look at my one I just send removed the "new" between the throw and gradleException and save and restart android studio an dthat will fix the problem

@CorneluisTech789
Copy link

U don't need to replace it with 'FileNotFoundException' just take out the word new and restart the software android studio that's all and it's that easy

Hope u come right

@chitgoks
Copy link

@CorneluisTech789 is right. weird... same thing with Properties, just remove the new keyword. why is this?

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
t: gradle "flutter build" and "flutter run" on Android tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

No branches or pull requests