Gradle failure A problem occurred evaluating project ':app'
I changed my project/build.gradle file like following:
// ...
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.2'
// ...
}
In here, my project uses kotlin-gradle-plugin which has a dependency on "$kotlin_version"
. And Android Gradle plugin supports only Kotlin Gradle plugin version 1.3.0 and higher. So, I changed the value of kotlin_version on the same "build.gradle" file.
Just change
ext.kotlin_version = '1.2.71'
to
ext.kotlin_version = '1.3.0'
And, also you need to go to "android/gradle/wrapper/gradle-wrapper.properties" file and change it to this:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip
Now, run "flutter clean" and then "flutter run" command. It works perfectly !
I had the same issue changing google services classpath from 4.3.0 to 4.2.0 made that fixed.
classpath 'com.google.gms:google-services:4.3.0'
change this into
classpath 'com.google.gms:google-services:4.2.0'
I managed to solve the problem by creating a new project with flutter create
and copying the lib folder over to the new project and also the changes needed for the gradle (also changing the google-services classpath version to 4.2.0) and pubspec.
Update 2022-04-26:
It is possible that the root cause is using a Kotlin version which is not compatible with older versions of Gradle. A possible fix is downgrading the version of Kotlin below 1.2.71, or more sensibly, upgrading Gradle.
Update 2019-12-13:
As of Flutter 1.12 (stable) released on Dec 11 2019, Flutter boilerplate now includes gradle distribution 5.6.2 and plugin version 3.5.0 which will hopefully make this a historical SO question. Plugin version 3.5.3 is current, but even version 3.5.0 should fix the issue as initially reported.
Original answer:
This appears to be caused by the Flutter boilerplate specifying an old version of the gradle plugin. I'm still unclear if Flutter package updates in pubspec.yaml/lock are triggering the issue, I rolled back a way but it was still present here.
For some reason this affects my Windows 10 system, but not my Mac development environment. Both are up-to-date (Flutter 1.7.8+hotfix.4) and on the same versions of everything as far as I'm aware. On account of this Windows path separators are used in the notes below.
In android\gradle\wrapper\gradle-wrapper.properties
the Flutter boilerplate specifies a gradle distribution of 4.10.2, which supports a plugin version of up to 3.3.2. However, android\build.gradle
only depends on plugin version 3.2.1 (classpath 'com.android.tools.build:gradle:3.2.1'
). It's unclear why the Flutter boilerplate isn't more internally consistent.
To resolve, change com.android.tools.build:gradle:3.2.1
=> com.android.tools.build:gradle:3.3.2
, run flutter clean
and try the build again.
According to the gradle release notes, the current (July 2019) version of the plugin and gradle are 3.4.2 and 5.1.1 respectively. I don't know if Flutter officially supports this version, although it seems to work on my project here and a clean build is markedly faster. The release notes cover some of the changes from 3.2.x => 3.3.x => 3.4.x.
To upgrade to the current version, edit android\gradle\wrapper\gradle-wrapper.properties
to source gradle 5.1.1, and then you're able to upgrade the gradle plugin to 3.4.2.
gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
build.gradle:
classpath 'com.android.tools.build:gradle:3.4.2'
Note that once gradle 5.1.1 is being used, you can still set the plugin version back to 3.2.1 to reproduce the issue.
I've opened an issue with the Flutter team to try and understand this better and will update this answer if they come back with anything concrete.