title: Xamarin Android's FirebaseInstanceId.Instance.Token throws error instead of returning FCM token
body: <p>I was following some tutorials (seen below) on how to connect Firebase to the Xamarin Android app to use Push Notifications. My team already had it working but after making iOS work and going back to Android Push notifications, I noticed that it had issues.</p>
  
  <p>Here is the part with issues:</p>
  
  <pre><code>    private string GetFirebaseInstanceId()
      {
          FirebaseApp.InitializeApp(this);
          var FCMToken = FirebaseInstanceId.Instance.Token;
          if (string.IsNullOrEmpty(FCMToken))
          {
              return null;
          }
          Log.Debug(Tag, $"FCM Registration Token: {FCMToken}");
          return FCMToken;
      }
  </code></pre>
  
  <p>When trying to get the token, I get this error "Java.Lang.IllegalStateException: Default FirebaseApp is not initialized in this process {packageName}. Make sure to call FirebaseApp.initializeApp(Context) first."</p>
  
  <p>That is why I added FirebaseApp.InitializeApp(this) before trying to get the token, but it made no difference. I have also tried doing this in the Spash activity and Main activity, but it did not fix the issue.</p>
  
  <p>I have also made sure that the build action of google-services.json is GoogleServicesJson.</p>
  
  <p>As for the code changes that I made, here are some of notable ones I think might be relevant:</p>
  
  <ul>
  <li>Added more permissions in the manifest so the map is not displayed as blank grey rectangle after installation from the Play Store.</li>
  <li>Resource.Designer.cs has changes so I checked it in.</li>
  </ul>
  
  <p>I checked the history of the file containing the snipped above and it the particular method wasn't changed.</p>
  
  <p>Here some tutorials that I followed:</p>
  
  <ul>
  <li><a href="https://developer.xamarin.com/guides/android/application_fundamentals/notifications/remote-notifications-with-fcm/" rel="nofollow noreferrer">Xamarin Android Firebase Documentation</a></li>
  <li><a href="https://firebase.google.com/docs/cloud-messaging/android/client" rel="nofollow noreferrer">Firebase Android Documentation</a></li>
  </ul>
  
  <p>What can I do to properly retrieve the FCM registration token?</p>