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

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐