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

简介: 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.

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.

image.png


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是否被引用


相关文章
|
前端开发 Java
Java Process类Runtime.getRuntime().exec() 执行bat脚本程序
Java Process类Runtime.getRuntime().exec() 执行bat脚本程序
1265 0
|
算法 安全 Ubuntu
8 种 Java 内存溢出之八 -Kill process or sacrifice child
8 种 Java 内存溢出之八 -Kill process or sacrifice child
|
安全 算法 Oracle
【Java用法】加密异常----Caused by: java.security.InvalidKeyException: Illegal key size or default parameters
【Java用法】加密异常----Caused by: java.security.InvalidKeyException: Illegal key size or default parameters
1841 0
|
网络协议 Java Shell
java spring 项目若依框架启动失败,启动不了服务提示端口8080占用escription: Web server failed to start. Port 8080 was already in use. Action: Identify and stop the process that’s listening on port 8080 or configure this application to listen on another port-优雅草卓伊凡解决方案
java spring 项目若依框架启动失败,启动不了服务提示端口8080占用escription: Web server failed to start. Port 8080 was already in use. Action: Identify and stop the process that’s listening on port 8080 or configure this application to listen on another port-优雅草卓伊凡解决方案
1424 7
|
存储 Java
Java“(array) <X> Not Initialized” (数组未初始化)错误解决
在Java中,遇到“(array) &lt;X&gt; Not Initialized”(数组未初始化)错误时,表示数组变量已被声明但尚未初始化。解决方法是在使用数组之前,通过指定数组的大小和类型来初始化数组,例如:`int[] arr = new int[5];` 或 `String[] strArr = new String[10];`。
852 2
### Cause: java.sql.SQLException: Field ‘id‘ doesn‘t have a default value; Field ‘id‘ doesn‘t have
### Cause: java.sql.SQLException: Field ‘id‘ doesn‘t have a default value; Field ‘id‘ doesn‘t have
|
SQL Java 数据库连接
Cause: java.sql.SQLException: Field ‘id‘ doesn‘t have a default value; Field ‘id‘ doesn‘t have a de
Cause: java.sql.SQLException: Field ‘id‘ doesn‘t have a default value; Field ‘id‘ doesn‘t have a de
|
Java API
Dating Java8系列之default默认方法
Dating Java8系列之default默认方法
391 0
Dating Java8系列之default默认方法
|
Java 数据库 Spring
Failed to instantiate [java.lang.Long]: No default constructor found;nested exception is java.lang()
Failed to instantiate [java.lang.Long]: No default constructor found;nested exception is java.lang()
Failed to instantiate [java.lang.Long]: No default constructor found;nested exception is java.lang()
|
Java Python
【已解决】RuntimeError Java gateway process exited before sending its port number
【已解决】RuntimeError Java gateway process exited before sending its port number
921 0