未找到 ID 为“com.google.gms.google-services”的插件。[ 安卓 ]

7 java android firebase

我正在设置 firebase

Firebase 官方链接
我正在关注此链接,我的第二步正确地完成了它,但我认为我在第三步和第四步中犯了一些错误我的代码中有一些我不明白的缺陷,
如果您能,我会很高兴帮助我们。

构建 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
}
Run Code Online (Sandbox Code Playgroud)

构建摇篮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'
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*ler 15

该插件需要在根目录中引用build.gradle

plugins {
    id 'com.android.application' version '7.3.1' apply false
    id 'com.android.library' version '7.3.1' apply false
    id 'com.google.gms.google-services' version '4.3.14' apply false
}
Run Code Online (Sandbox Code Playgroud)

然后可以将其应用到模块中build.gradle

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'
}
Run Code Online (Sandbox Code Playgroud)


Vis*_*eep 1

你可以尝试一下:

编辑

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
}
Run Code Online (Sandbox Code Playgroud)

build.gradle(Module: AppName)

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

android {
 // rest code ....
}

dependencies {
 // here your dependencies
}
Run Code Online (Sandbox Code Playgroud)

并确保您已添加google-services.json到您的项目中。

我会建议您通过 android studio 的firebase 工具连接 firebase并手动避免它。