如何将 com.google.gms:google-services:4.3.14 添加到我的 Android 项目中?

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

提问人:zeus 提问时间:11/23/2022 最后编辑:Gabriele Mariottizeus 更新时间:11/24/2022 访问量:13212

问:

当我阅读此文档时:https://developers.google.com/android/guides/google-services-plugin 他们说:

在 Android 应用程序中启用 Google API 或 Firebase 服务时,您可能需要将 google-services 插件添加到 您的 build.gradle 文件:

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

然后他们也说:

为服务所需的基本库添加依赖项 已启用。此步骤要求您应用 Google 服务 Gradle 插件,如下所示: apply plugin: “com.google.gms.google 服务”

所以我在最新版本的 Android Studio 中启动了一个空白的新 android 项目,并且我有根 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
}

在 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"
}

所以我必须在其中添加

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

apply plugin: 'com.google.gms.google-services' ?
Firebase Android-Studio Android-gradle-plugin google-play-services

评论

0赞 Alex Mamo 11/23/2022
你看到这个答案了吗?有帮助吗?

答:

18赞 Gabriele Mariotti 11/24/2022 #1

在块中的文件中,添加build.gradleplugins

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

然后将其应用到模块文件中:build.gradle

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

评论

0赞 mentat 10/10/2023
对于 flutter,我还需要添加 build.gradle 块。classpath 'com.google.gms:google-services:4.3.14'dependencies