skip to Main Content

FAILURE: Build failed with an exception.

  • Where:
    Build file ‘C:UsersASUSDocumentsfypandroidbuild.gradle’ line: 7

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

Could not find method classpath() for arguments [com.google.gms:google-services:4.4.1] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

android/build.gradle
enter image description here

android/app/build.gradle
enter image description here

2

Answers


  1. You can add your compatible version of this codes to the top of android/build.gradle file. Mine is working like that.

    buildscript {
        dependencies {
            classpath 'com.android.tools.build:gradle:8.1.0'
            classpath 'com.google.gms:google-services:4.4.2'
            classpath 'com.google.firebase:firebase-crashlytics-gradle:3.0.2'
        }
    }
    
    plugins{
        id "com.google.gms.google-services" version '4.4.2' apply false
        id ("com.google.firebase.crashlytics") version '3.0.2' apply false
    }
    

    also settings.gradle is like that

    pluginManagement {
        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")
    
        repositories {
            google()
            mavenCentral()
            gradlePluginPortal()
        }
    }
    
    plugins {
        id "dev.flutter.flutter-plugin-loader" version "1.0.0"
        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
    }
    
    include ":app"
    
    Login or Signup to reply.
  2. You mix imperative and declarative to apply gradle plugin.

    Please follow this guide and ensure there is no more mixing:
    https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply

    And to apply correctly the gms plugin:

    Remove dependencies section from your android/build.gradle

    android/settings.gradle

    plugins {
    // ...
    id "com.google.gms.google-services" version "4.3.15" apply false
    }
    

    android/app/build.gradle

    plugins {
      // ...
      id 'com.google.gms.google-services'
    }
    

    You can find the complete migration here: https://docs.flutter.dev/release/breaking-changes/flutter-gradle-plugin-apply#google-mobile-services-and-crashlytics

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search