首页 > 解决方案 > 在构建 gradle 中将类路径“com.google.gms:google-services:4.3.8”更改为 4.3.9 时,FirebaseApp 未初始化错误

问题描述

我将我的 Android 项目更新为 7.0.2,这改变了

classpath 'com.google.gms:google-services:4.3.8' to 
classpath 'com.google.gms:google-services:4.3.9'.

更新后,我开始收到一个错误,即 FirebaseApp 未初始化或构建 Gradle 不包括 gms: google services。

我试图添加

FirebaseApp.initializeApp(mycontext);

方法也在触发错误的我的 Firebase 令牌异步任务中,但这无济于事。

有人可以建议如何解决吗?

标签: androidbuild.gradle

解决方案


在您的应用级 Gradle 文件中,在文件底部添加“应用插件”行以启用 Gradle 插件:

apply plugin: 'com.android.application'



dependencies {
  // ...
  implementation 'com.google.firebase:firebase-bom'
  // If getting a "Could not find" error? Make sure you have the latest Google 
  // Repository in the Android SDK manager
}

//ADD THIS LINE AT BOTTOM
apply plugin: 'com.google.gms.google-services'

或者你可以像这样添加插件:

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

现在,同步两个 gradle 文件


推荐阅读