Simple FirebaseApp is crashing after installation

59 Views Asked by At

I am learning to implement firebase in an android studio. And I have studied various tutorials on this subject. So in order to minimize the chances of making mistakes, I decided to implement a simple token generated scripts in my mainactivity inside the onCreate() method; these codes below:

FirebaseInstanceId.getInstance().getInstanceId()
    .addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {

        @Override
        public void onComplete(@NonNull Task<InstanceIdResult> task) {
            if (!task.isSuccessful()) {

                Log.w(TAG, "getInstanceId failed", task.getException());
                return;

            }

            String token = task.getResult().getToken();

        }
    });

Then the app keeps crashing after generating its apk.

Then following codes were then implemented:

FirebaseInstanceId.getInstance().getInstanceId().addOnSuccessListener( MainActivity.this,  new OnSuccessListener<InstanceIdResult>() {
     @Override
     public void onSuccess(InstanceIdResult instanceIdResult) {

           String newToken = instanceIdResult.getToken();

     }
 });

I am using latest dependency :

  • firebase messaging:17.6.0
  • firebase-core:16.0.8

The problem is each time I generated the APK , the app keeps crashing with error message "app has stopped". But when I built any other android app without firebase ,the app will work perfectly.

0

There are 0 best solutions below