Reputation: 1063
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'
}
Upvotes: 97
Views: 116096
Reputation: 392
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 FileNotFoundException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
Upvotes: 2
Reputation: 137
may be your current flutter version is higher than that specified in pubspec.yaml: Change these line to be lower or equal to your current version
environment:
sdk: ">=2.7.0 <3.0.10"
Upvotes: -1
Reputation: 425
For me, it's because of invalid file
pubspec.yaml
Please re-check the file configurations.
Upvotes: -1
Reputation: 1
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
Upvotes: -1
Reputation: 1190
It worked for me(android studio version: 4.1, flutter version: 2.5)
Upvotes: 3
Reputation: 526
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.
Upvotes: 6
Reputation: 21
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.
Upvotes: 2
Reputation: 3187
This issue is due to not pointing to correct Android API Platform
Solution :
In the Android Studio File > Project Structure
Upvotes: 190
Reputation: 9
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.
Upvotes: 0
Reputation: 115
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.")
}
. . . . . . . .
Upvotes: 10
Reputation: 1277
It's working for me:
GradleException()
to FileNotFoundException()
under android/app/build_gradle since it's not supported in the Java version of Android API 29
Solution foundUpvotes: 4
Reputation: 41089
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.
Upvotes: 103
Reputation: 1
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).
Upvotes: 0
Reputation: 377
Go to File -> Project Structure -> Modules -> Select your project -> apply your API
Upvotes: 21
Reputation: 21
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'
Upvotes: 1
Reputation: 21
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
Upvotes: 2
Reputation: 21
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
Upvotes: 2
Reputation: 19578
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
Upvotes: 29
Reputation: 178
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.
Upvotes: 1
Reputation: 268
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'
}
}
Upvotes: 4