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


相关文章
|
3月前
|
存储 Java
Java“(array) <X> Not Initialized” (数组未初始化)错误解决
在Java中,遇到“(array) &lt;X&gt; Not Initialized”(数组未初始化)错误时,表示数组变量已被声明但尚未初始化。解决方法是在使用数组之前,通过指定数组的大小和类型来初始化数组,例如:`int[] arr = new int[5];` 或 `String[] strArr = new String[10];`。
104 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
|
6月前
|
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
641 0
|
8月前
|
Java API
Dating Java8系列之default默认方法
Dating Java8系列之default默认方法
79 0
Dating Java8系列之default默认方法
|
数据库
java.sql.SQLException: Field ‘id‘ doesn‘t have a default value
java.sql.SQLException: Field ‘id‘ doesn‘t have a default value
|
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 C++
Java权限修饰符(包括Java8 default介绍)
Java权限修饰符(包括Java8 default介绍)
299 0
Java权限修饰符(包括Java8 default介绍)
|
Java 程序员 Spring
Java 在接口Interface中 使用关键字 default
Java 在接口Interface中 使用关键字 default
498 0
Java 在接口Interface中 使用关键字 default
|
Java Scala Python
Java8新特性之Lambda表达式,函数式接口,方法引用和default关键字
前言 文本已收录至我的GitHub仓库,欢迎Star:github.com/bin39232820… 种一棵树最好的时间是十年前,其次是现在
183 0