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

Viewed 272

I was Setup firebase

Firebase Official link
I'm Following This Link my 2nd step went through it correctly, but I think I am doing some mistakes in 3rd & the 4th There are some flaws in my code that I don't understand,
I will be glad if you can help us.

build Gradle:- Project

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

task clean(type: Delete) {
delete rootProject.buildDir
}

build Gradle: Module

plugins {
 id 'com.android.application'
}

//code here..
apply plugin: 'com.google.gms.google-services'

android {
 compileSdk 32

 defaultConfig {
    applicationId "com.company.myfire"
    minSdk 21
    targetSdk 32
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
 }

 buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard- 
 rules.pro'
    }
 }
 compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
 }
}

dependencies {
 classpath 'com.google.gms:google-services:4.3.10'
 implementation 'androidx.appcompat:appcompat:1.4.1'
 implementation 'com.google.android.material:material:1.6.0'
 implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
 implementation platform('com.google.firebase:firebase-bom:30.0.0')
 implementation 'com.google.firebase:firebase-analytics'
 testImplementation 'junit:junit:4.13.2'
 androidTestImplementation 'androidx.test.ext:junit:1.1.3'
 androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
2 Answers

The plugin needs to be added to class-path:

plugins {
    id 'com.android.application' version '7.2.0' apply false
    id 'com.android.library' version '7.2.0' apply false
    id 'com.google.gms.google-services' version '4.3.10' apply false
}

Then it can be applied in a module:

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

You can give it a try :

Edit

in build.gradle(Project: AppName)

buildscript {
  dependencies {
     classpath 'com.google.gms:google-services:4.3.10'
  }
} // Top-level build file where you can add configuration options common 
  // to all sub-projects/modules.
plugins {
   id 'com.android.application' version '7.2.0' apply false
   id 'com.android.library' version '7.2.0' apply false
}

task clean(type: Delete) {
   delete rootProject.buildDir
}

in build.gradle(Module: AppName) :

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

android {
 // rest code ....
}

dependencies {
 // here your dependencies
}

and make sure you have added google-services.json to your project.

and I will recommend you to connect firebase by android studio's firebase tool and avoid it manually.

Related