how to add com.google.gms:google-services:4.3.14 in my android project?

Issue

When I read this doc: https://developers.google.com/android/guides/google-services-plugin they say :

As part of enabling Google APIs or Firebase services in your Android application you may have to add the google-services plugin to
your build.gradle file:

dependencies {
    classpath 'com.google.gms:google-services:4.3.14'
    // ...
}

then they say also :

Add dependencies for basic libraries required for the services you
have enabled. This step requires that you apply the Google Services
Gradle plugin in your app/build.gradle file, like so: apply plugin:
‘com.google.gms.google-services’

so i start a blank new android project in the very last version of android studio and I have for the root build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    id 'com.android.application' version '7.3.1' apply false
    id 'com.android.library' version '7.3.1' apply false
}

and in app/build.gradle:

plugins {
    id 'com.android.application'
}

android {
    namespace 'app.dependencieswalker'
    compileSdk 32

    defaultConfig {
        applicationId "app.dependencieswalker"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
        implementation "com.alcinoe:alcinoe-firebase:1.0.0"
}

so where I must add the

dependencies {
    classpath 'com.google.gms:google-services:4.3.14'
    // ...
}

and

apply plugin: 'com.google.gms.google-services' ?

Solution

In your root build.gradle file in the plugins block add

plugins {
    //....
    id 'com.google.gms.google-services' version '4.3.14' apply false
}

Then apply it in the module build.gradle file with:

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
}

Answered By – Gabriele Mariotti

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published