FirebaseApp.initializeApp(Context); Android error;

前端 未结 3 1619
青春惊慌失措
青春惊慌失措 2021-01-25 08:23

I\'ve spent about three days now trying to solve a java error that\'s stopping me from finishing my chat app! And of course it\'s a firebase error! I\'m new to Android Developin

3条回答
  •  攒了一身酷
    2021-01-25 08:55

    Add:

    apply plugin: 'com.google.gms.google-services' 
    

    in your app gradle file

    According to the docs:

    As said in the docs:

    Any FirebaseApp initialization must occur only in the main process of the app. Use of Firebase in processes other than the main process is not supported and will likely cause problems related to resource contention.

    you need to initialize it not in the activity.

    add an application class to your manifest example:

          

    then do this:

    public class MyApplication extends Application {
      @Override
    public void onCreate() {
        super.onCreate();
       FirebaseApp.initializeApp(this);
    }
    

    and remove the initialization from the activity. You need to initialize it in the application class which is the base class.

提交回复
热议问题