android - 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
我尝试设置一个全新的应用程序并且它可以工作,但实际上不适用于我的项目。我认为存在依赖问题,但没有错误或提示。
我尝试了许多不同的版本,似乎没有一个工作。
你有解决方案吗?
解决方案
问题tools:node="replace"
出在子模块的 AndroidManifest.xml 中。在我删除它并修复 Manifest-Merger 问题后,它工作正常!
谷歌真的应该给我们一个小提示,如果您tools:node="replace"
在项目中的任何地方使用 Firebase 将不会启动。
推荐阅读
- python - 在 Xcode 中创建项目时如何更改 python 版本
- parsing - Lucene 解析器异常中标签的含义
- r - 如何将重复的功能折叠成主功能?
- python - 使用 pywavelets 的逆平稳小波变换
- c# - 在 xUnit 中管理多个级别的收集装置/从 NUnit 移植
- laravel - Laravel 8.61.0 - 登录后重定向不起作用
- git - 为什么 RunCommand 或自定义脚本扩展无法识别术语 git?
- c# - 是否可以仅使用用户和密码从我的 .net 核心应用程序登录到 Azure?
- docker - Docker 支持文件系统作为 AWS efs
- c# - 如何修复错误:“dataGridView1”控件是从不同的线程访问的