skip to Main Content

Just created a new project and am getting this error:

A problem occurred evaluating project ‘:app’.

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

I was following an online class but may have missed something (not sure how old the class is).

Here is my build.gradle under app

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

android {
    compileSdkVersion flutter.compileSdkVersion
    ndkVersion flutter.ndkVersion

    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.flutter_feed"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
        minSdkVersion flutter.minSdkVersion
        targetSdkVersion flutter.targetSdkVersion
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    id 'com.google.gms.google-services'
}

I tried using my build.gradle code from an already working app but that didn’t work.

Here is my main.dart:

void main() async {

  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();

  runApp(new MaterialApp(
    home: new Home(),
  ));
}

google-services location

pubspec.yaml

3

Answers


  1. Chosen as BEST ANSWER

    Silly mistakes..

    Edited google-services (1).json to google-services.json

    Changed

    dependencies {
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
        id 'com.google.gms.google-services'
    }
    

    to:

    dependencies {
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
        implementation platform('com.google.firebase:firebase-bom:30.4.1')
       
    }
    

    And changed/moved

    id 'com.google.gms.google-services'
    

    to:

    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"
    

  2. If its the latest flutter sdk version like 3.3.5;
    change – 'id 'com.google.gms.google-services'
    //the above is from firebase its like `plugins {
    id ‘com.android.application’

    // Add the Google services Gradle plugin
    id ‘com.google.gms.google-services’


    }to -apply plugin:’com.google.gms.google-services’`

    since in the build.dart file in the app folder is apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

    resolved should be like apply plugin: 'com.google.gms.google-services' apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

    Login or Signup to reply.
  3. My mistake

    don’t do This
    [apply: ‘com.google.gms.google-services’]

    Do this
    [apply plugin: ‘com.google.gms.google-services’]

    I Forget to write a plugin and I get this error
    // Works For me

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