Leena Marie
Leena Marie

Reputation: 347

Could not find method id() for arguments [com.google.gms.google-services]

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

Upvotes: 3

Views: 9688

Answers (3)

Amit Bidlan
Amit Bidlan

Reputation: 81

I had the same issue and it was a typo error Try: classpath 'com.google.gms:google-services:4.3.15':

in your project's gradle file. The difference is google.gms:google instead of google.gms.google This will work.

Upvotes: 0

Ezekiel Maina
Ezekiel Maina

Reputation: 11

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"

Upvotes: 1

Leena Marie
Leena Marie

Reputation: 347

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"

Upvotes: 4

Related Questions