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

本文探讨了在Android项目中接入Firebase Cloud Messaging (FCM)时遇到的`DefaultFirebaseApp is not initialized in this process`错误,并提供了排查和解决步骤。通过检查`build.gradle`文件、确保`google-services.json`文件正确放置、依赖库版本、`Application`类的初始化方法以及`AndroidManifest.xml`中的引用,可以有效定位并解决该问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Android 接入 FCM 报错

        报错信息如下: 

java.lang.RuntimeException: Unable to create application com.ads.app.MyApplication: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.ads.app. Make sure to call FirebaseApp.initializeApp(Context) first.
Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.ads.app. Make sure to call FirebaseApp.initializeApp(Context) first.

1、检查项目\build.gradle

 dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.google.gms:google-services:4.2.0'
    }

2、检查google-services.json

        是否放在app\目录下,必须保证google-services.json里面有当前包的包名

3、检查app\build.gradle

dependencies {
    implementation 'com.google.android.gms:play-services-auth:15.0.1'
    implementation 'com.google.firebase:firebase-core:17.2.0'
    implementation 'com.google.firebase:firebase-iid:20.0.0'
    implementation 'com.google.firebase:firebase-messaging:20.0.0'
    implementation 'com.android.installreferrer:installreferrer:1.0'
}

       apply plugin: 'com.google.gms.google-services'是否放在app\build.gradle底部

4、检查Application

@Override
    public void onCreate() {
        super.onCreate();
        FirebaseApp.initializeApp(this);
        initFirebase();
    }
private void initFirebase(){
        FirebaseInstanceId.getInstance().getInstanceId()
                .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
                    @Override
                    public void onComplete(@NonNull Task<InstanceIdResult> task) {
                        if (!task.isSuccessful()) {
                            MLog.e( "getInstanceId failed"+task.getException());
                            return;
                        }
                        String token = task.getResult().getToken();
                    }
                });
    }

5、检查AndroidManifest.xml

        Application是否被引用。

相关推荐

Google Play 登录失败报错分析-CSDN博客文章浏览阅读135次。一、场景一、场景点击 登录谷歌按钮 报错:902 一> com.google.android.gms.common.api.ApiException: 10二、报错信息分析2.1 查看网络是否开启(12501)(1)国内需要虚拟专用网络(VPN)(2)非内部测试账号,需要检查该账号所属地区/国家与发布地区/国家一致。2.2 查看代码以及配置项2.2.1 检查 Google Play Console 配置检查 SHA-1 签名证书需要在创建应用。使用谷歌再签名获取SHA1。https://shuaici.blog.csdn.net/article/details/140551646

Google Pay支付遇到的问题-CSDN博客文章浏览阅读2.1w次,点赞6次,收藏12次。本文详细介绍了在使用Google Pay支付时可能遇到的各种问题及解决方案,包括错误代码[DF-AA-01]和[DF-AA-20],支付失败的原因和处理方法,如检查权限、版本一致性、用户添加等。此外,还提到了支付方式的注意事项,如信用卡、手机计费和电子钱包的使用。对于Google Play登录和Facebook登录问题,文中也提供了相应的解决建议。https://shuaici.blog.csdn.net/article/details/85213947

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

帅次

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值