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


相关文章
|
10月前
|
前端开发 Java
Java Process类Runtime.getRuntime().exec() 执行bat脚本程序
Java Process类Runtime.getRuntime().exec() 执行bat脚本程序
547 0
|
1月前
|
网络协议 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-优雅草卓伊凡解决方案
73 7
|
5月前
|
存储 Java
Java“(array) <X> Not Initialized” (数组未初始化)错误解决
在Java中,遇到“(array) &lt;X&gt; Not Initialized”(数组未初始化)错误时,表示数组变量已被声明但尚未初始化。解决方法是在使用数组之前,通过指定数组的大小和类型来初始化数组,例如:`int[] arr = new int[5];` 或 `String[] strArr = new String[10];`。
146 2
|
10月前
|
算法 安全 Ubuntu
8 种 Java 内存溢出之八 -Kill process or sacrifice child
8 种 Java 内存溢出之八 -Kill process or sacrifice child
### 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
|
8月前
|
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
|
安全 算法 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
705 0
|
10月前
|
Java API
Dating Java8系列之default默认方法
Dating Java8系列之default默认方法
92 0
Dating Java8系列之default默认方法
|
10月前
|
Java Python
【已解决】RuntimeError Java gateway process exited before sending its port number
【已解决】RuntimeError Java gateway process exited before sending its port number
351 0
|
Java
Java Virtual Machine Process Status Tool <jps>
jps(Java Virtual Machine Process Status Tool)是java提供的一个显示当前所有java进程pid的命令
128 0

热门文章

最新文章