Setiings.gradle Error:Build failed with an exception

I Shared the Error & Settings.gradle file below, I have been facing the below issues since I connected with Firebase It’ll be helpful if you checkout & give me some guidance to solve the issue Thanks in advance.

FAILURE: Build failed with an exception.

* Where:
Settings file '/home/Documents/Quiz_app_flutter/quiz_app/android/settings.gradle' line: 30

* What went wrong:
Could not compile settings file '/home/Documents/Quiz_app_flutter/quiz_app/android/settings.gradle'.
> startup failed:
  settings file '/home/Documents/Quiz_app_flutter/quiz_app/android/settings.gradle': 30: only buildscript {}, pluginManagement {} and other plugins {} script blocks are allowed before plugins {} blocks, no other statements are allowed
  
  For more information on the plugins {} block, please refer to https://docs.gradle.org/8.3/userguide/plugins.html#sec:plugins_block in the Gradle documentation.
  
   @ line 30, column 1.
     plugins {
     ^
  
  1 error


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

settings.gradle File

// Define plugin repositories
pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }

    // Define the Flutter SDK path
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null : "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }()

    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
}

// Define dependency repositories
dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
    }
}

// The plugins block must come after pluginManagement and dependencyResolutionManagement
plugins {
    id "com.android.application" version "8.1.0" apply false
    id "org.jetbrains.kotlin.android" version "1.8.22" apply false
    id "com.google.gms.google-services" version "4.4.2" apply false
    id "dev.flutter.flutter-gradle-plugin" version "1.0.0"
}

// Include the app module
include(":app")

The error message is imho quite clear and explicit.
Which part is unclear?

@Vampire You’re right, Despite following Gradle’s Plugin Documentation and ensuring compliance, the build fails with an exception, again and again,
is there anything incorrect in the current settings.gradle configuration?
Or are there specific flutter/gradle plugin interactions causing the issue?

Yes, and the error tells you exactly what. Hence my question what is unclear.


Besides that, I strongly recommend switching to Kotlin DSL. By now it is the default DSL, you immediately get type-safe build scripts, actually helpful error messages if you mess up the syntax, and amazingly better IDE support if you use a good IDE like IntelliJ IDEA or Android Studio.

1 Like