Tags
Android
Asked 3 years ago
5 Oct 2021
Views 1820
Rene

Rene posted

Android - Default FirebaseApp is not initialized

i am trying to get FCM registration Token.


   FirebaseMessaging.getInstance().getToken()
                .addOnCompleteListener(new OnCompleteListener<String>() {
                    @Override
                    public void onComplete(@NonNull Task<String> task) {
                        if (!task.isSuccessful()) {
                            Log.w(TAG, "Fetching FCM registration token failed", task.getException());
                            return;
                        }

                        // Get new FCM registration token
                        String token = task.getResult();

                        // Log and toast
                         Log.d(TAG, token);
                        Toast.makeText(SigninActivity.this, "Token", Toast.LENGTH_SHORT).show();
                    }
                });

i am getting FATAL EXCEPTION on using the above FirebaseMessaging code


FATAL EXCEPTION: main
    Process: com.exaorapp, PID: 28807
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.exaorapp/com.exaorapp.ui.SigninActivity}: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.exaorapp. Make sure to call FirebaseApp.initializeApp(Context) first.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2723)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2784)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1523)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:163)
        at android.app.ActivityThread.main(ActivityThread.java:6238)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
     Caused by: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.exaorapp. Make sure to call FirebaseApp.initializeApp(Context) first.
Nilesh

Nilesh
answered Oct 5 '21 00:00

in the build.gradle file , put this line at the end of the file


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