首页 > 解决方案 > FirebaseApp 在此过程中未初始化 - 此外 FirebaseApp.initializeApp() 不起作用。依赖问题?

问题描述

我将以下行添加到项目 gradle 文件中:

classpath 'com.google.gms:google-services:4.0.0'

这进入模块 gradle 文件:

dependencies {

    ...    

    // GPS
    implementation 'com.google.android.gms:play-services-location:16.0.0'

    // FireBase
    implementation 'com.google.firebase:firebase-core:16.0.4'
    implementation 'com.google.firebase:firebase-iid:17.0.4'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'

    implementation 'com.google.android.gms:play-services-gcm:16.0.0'
}

apply plugin: 'com.google.gms.google-services'

并将其添加到 AndroidManifest.xml

<service
        android:name=".pushclient.PushService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT"/>
        </intent-filter>
</service>

google-services.json从 FireBase 控制台下载并将其放置在正确的位置

但是在尝试使用 Firebase 时出现以下错误:

Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process

当我手动初始化它并尝试获取 ID 时,我收到此错误:

Caused by: java.lang.IllegalStateException: FirebaseInstanceId.getInstance() must not be null

我尝试设置一个全新的应用程序并且它可以工作,但实际上不适用于我的项目。我认为存在依赖问题,但没有错误或提示。

我尝试了许多不同的版本,似乎没有一个工作。

你有解决方案吗?

标签: androidfirebasegoogle-play-services

解决方案


问题tools:node="replace"出在子模块的 AndroidManifest.xml 中。在我删除它并修复 Manifest-Merger 问题后,它工作正常!

谷歌真的应该给我们一个小提示,如果您tools:node="replace"在项目中的任何地方使用 Firebase 将不会启动。


推荐阅读