How to solve gradle failure a problem occured evaluating project In Flutter ?

· 3 min read
How to solve gradle failure a problem occured evaluating project In Flutter
How to solve gradle failure a problem occured evaluating project In Flutter

Sometimes users started getting randomly because of Gradle. So in this article, we will go through How to solve Gradle failure a problem Occurred evaluating the project in Flutter?

How to solve Gradle failure a problem occurred evaluating project In Flutter?

This appears to be caused by 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.

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‘).

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 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'

Users can make changes in my project/build.gradle file like the 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'
    // ... 
}

Our 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.

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 the “flutter clean” and then the “flutter run” command.

Tried changing ‘com.google.gms:google-services: to various versions.

User can also give try to below steps:

  • Create a new flutter project.
  • Copy all the source files and folders.
  • May need to change copied folders to ‘sources’ File>Project Structure> Project Settings>project name>Sources select the folder then click ‘Source’ above the file name.
  • Copy pubspec.yaml file over and run Pub git
  • Close the project
  • Open the project again

Conclusion:

In this article, we have been through how to Solve Gradle failure a problem occurred evaluating the project in Flutter?

Thanks for Reading.
Keep Learning !!! Keep Fluttering !!!

FlutterAgency.com is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget GuideFlutter ProjectsCode libs and etc.

FlutterAgency.com is one of the most popular online portal dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge on Flutter.

Leave a Reply