Overnight I had this problem. Here is my build_gradle:

def localProperties = new 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.")
}

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 plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 30

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.game_rewards"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:multidex:1.0.3'
    classpath 'com.android.tools.build:gradle:3.3.2'
    classpath 'com.google.gms.google-services:4.3.10'

}

My error is :

Build file 'C:\Users\antoi\Documents\programmation\langages\flutter\game_rewards\android\build.gradle' line: 12

  • What went wrong: A problem occurred evaluating root project 'android'.

Plugin with id 'com.google.gms.google-services' not found.

I don't know why and can you please help me correct the errors. Thank you for your reply


Solution 1: immadisairaj

The error says that the plugin is not found because it is not added as dependency. You added the line but in a wrong place. Follow below for correcting it.

This is the link you followed to initialize https://firebase.flutter.dev/docs/manual-installation/android

Your code: (android/app/build.gradle)

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:multidex:1.0.3'
    classpath 'com.android.tools.build:gradle:3.3.2'
    classpath 'com.google.gms.google-services:4.3.10'
}

classpath 'com.google.gms.google-services:4.3.10'

This line in the above code causes the issue. From the initialisation, this line shouldn't be here and instead be in android/build.gradle

So, this part should look like

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:multidex:1.0.3'
    classpath 'com.android.tools.build:gradle:3.3.2'
}

Add this below line to android/build.gradle

classpath 'com.google.gms.google-services:4.3.10'

which should look like

buildscript {
  dependencies {
    // ... other dependencies
    classpath 'com.google.gms:google-services:4.3.8' // your version
  }
}

The above is directly from the link.


Solution 2: Thazin Soe

Please update your gradle version in build.gradle under project directory and rebuild again.

buildscript {
    repositories {
        // Gradle 4.1 and higher include support for Google's Maven repo using
        // the google() method. And you need to include this repo to download
        // Android Gradle plugin 3.0.0 or higher.
        google()
        ...
    }
    dependencies {
        classpath("com.android.tools.build:gradle:7.0.0")
    }
}

You can check detail in here
https://developer.android.com/studio/releases/gradle-plugin