Android Studio 如何在我的Android项目中添加com.google.gms:谷歌服务:4.3.14?

vmpqdwk3  于 2022-11-25  发布在  Android
关注(0)|答案(2)|浏览(186)

当我阅读此文档时:他们说:
作为在Android应用中启用Google API或Firebase服务的一部分,您可能需要将google-services插件添加到您的build.gradle文件中:

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

然后他们说:
为您已启用的服务所需的基本库添加依赖项。此步骤要求您在app/build.gradle文件中应用Google Services Gradle插件,如下所示:应用插件:“谷歌公司,通用汽车公司,谷歌服务”
因此,我在最新版本的android studio中启动了一个空白的新android项目,我为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
}

以及在app/built.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' ?
hfwmuf9z

hfwmuf9z1#

在您的rootbuild.gradle文件的plugins块中添加

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'
}
oxcyiej7

oxcyiej72#

您应该按如下方式修改根build.gradle:

plugins {
    id 'com.android.application' version '7.3.1' apply false
    id 'com.android.library' version '7.3.1' apply false
}

buildscript {
    repositories {
        mavenCentral()
        google()
    }
    dependencies {
        classpath 'com.google.gms:google-services:4.3.10'

    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

和应用程序/构建版本。gradle

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services' version '4.3.14' apply true
}

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

相关问题