'My flutter project broke and I get this gradle error

FAILURE: Build failed with an exception.

* What went wrong:
Could not create an instance of type org.gradle.invocation.DefaultGradle.
> Could not configure services using GradleScopeCompileServices.configure().

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
Exception: Gradle task assembleDebug failed with exit code 1

This is my build.gradle

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.google.gms:google-services:4.3.10'
        classpath 'com.android.tools.build:gradle:7.1.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

I tried so many things I changed flutter and gradle version and looked everywhere but I still get this error. It worked before now it just doesen't. Btw java version is set to 1.8



Solution 1:[1]

Faced the same issue.

Solution:

  1. Downgrade flutter version from 2.2.3 to 2.2.2
  2. Delete ~/.android folder.
  3. Restart android studio.

Solution 2:[2]

That kind of error has like a hundreds reason no one can know except to remember what you had done before. But anyway for better solution follow the following:

  • go to tools tab then flutter clean

  • go to file tab then invalidate cache and restart

  • follow the steps in this article to have the latest updates from Gradle

  • finally go to android folder then build gradle then on top right you will see edit file or something similar .. press on it and open new window and let it auto update till the end .. and better if you go to file into that new window then select project structure and manually see what the warning will it show to you and only press update

And don't forget to use the latest Flutter SDK.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hangman
Solution 2 halfer