Issue with generating FCM token

Sreenivasan, Sreejith 1,085 Reputation points
2026-01-05T10:00:11.4333333+00:00

I am getting below exception when launching the application:

Java.IO.IOException: 'SERVICE_NOT_AVAILABLE' [mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: Java.IO.IOException: SERVICE_NOT_AVAILABLE [mono-rt] at Plugin.Firebase.CloudMessaging.FirebaseCloudMessagingImplementation.GetTokenAsync() [mono-rt] at Xamarin.Forms.Clinical6.Login.EmailPMAPage.GetToken() in C:\Projects\Inventiva-MAUI\MAUI.Clinical6\UI\Views\Login\EmailPMAPage.xaml.cs:line 23 [mono-rt] at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state) [mono-rt] at Android.App.SyncContext.<>c__DisplayClass2_0.<Post>b__0() in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.App/SyncContext.cs:line 36 [mono-rt] at Java.Lang.Thread.RunnableImplementor.Run() in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:line 37 [mono-rt] at Java.Lang.IRunnableInvoker.n_Run(IntPtr jnienv, IntPtr native__this) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Java.Lang.IRunnable.cs:line 84 [mono-rt] at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V(_JniMarshal_PP_V callback, IntPtr jnienv, IntPtr klazz) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 22 [mono-rt] --- End of managed Java.IO.IOException stack trace ---

The issue is with the FCM token generation code below:

public EmailPMAPage()
{
    InitializeComponent();
    GetToken();
}

private async void GetToken()
{
    await CrossFirebaseCloudMessaging.Current.CheckIfValidAsync();
    var token = await CrossFirebaseCloudMessaging.Current.GetTokenAsync();
    Preferences.Default.Set("devicefcmtoken", token);
    Console.WriteLine($"FCM token::>> {token}");
}

I tried adding delay before it but no luck.

private async void GetToken()
{
    await Task.Delay(10000);
    await CrossFirebaseCloudMessaging.Current.CheckIfValidAsync();
    var token = await CrossFirebaseCloudMessaging.Current.GetTokenAsync();
}

I have added it on the login page constructor and there is an another page before loading to login page.

It was working fine before with a demo FCM project JSON files. Recently I replaced it with the original FCM project JSON files. After that only I am experiencing this issue.

Developer technologies | .NET | .NET Multi-platform App UI
0 comments No comments

Answer accepted by question author
Adiba Khan 2,355 Reputation points Microsoft External Staff
2026-01-05T10:48:30.46+00:00

Thanks for reaching out. The exception is returned by Google Play  Services when FCM cannot issue or refresh a registration token. This is not a .NET MAUI runtime issue-it normally occurs when the device or Firebase project configuration is not valid for the currently installed app build.

Root cause that commonly generate this error

One or more of the following is usually true:

  1. The google-services.json does not match the app package name in the Android manifest.
  2. The SHA-1 signing certificate is missing or changed in Firebase
  3. The app was not re-initialized after switching Firebase projects
  4. The device/emulator does not have valid Google Play Services.
  5. Network connectivity / FCM service is temporarily unavailable.

Recommended Resolution Steps:

  1. Uninstall the existing app from the device When switching to a different Firebase project, the previous InstanceID/token remains cached and prevents token creation. Uninstall -> Clean-> Re-install ensures a fresh FCM identity.
  2. Verify package name & applicationId match Check all three match exactly:
    1. Google-services.json
    2. AndroidManifest / MAUI package id
    3. Firebase project App registration
    If they do not match, FCM token generation will fail.
  3. Add SHA-1 for your signing key in Firebase Console If you are using a debug or release signing key, add the SHA-1 fingerprint for it in: Firebase Console-> Project Settings-> Android App-> Add SHA-1 Then download a new google-services.json and add it to the project. After replacing the file:
    1. Clean bin/obj
    2. Rebuild
    3. Re-install the app
  4. Ensure the JSON file is in the correct MAUI location Place it under:
       Platforms/Android/google-services.json
    
    Set build action to:
       GoogleServicesJson
    
  5. Test on a device with Google Play Services The error will occur on:
    1. Non-GMS emulators
    2. Devices without Play Services
    3. Out-of-date Play Services
    Update Play Services or test on a physical Android device.
  6. Call GetTokenAsync() only after validation succeeds Wrap your call defensively to avoid crashing:
       private async Task GetTokenAsync()
       {
       	try
       	{
       		var vaid = await CrossFirebaseCloudMessaging.Current.CheckIfValidAsync();
       		if (!valid)
       		{
       			Console.WriteLine("FCM not yet ready - retry later");
       			return;
       		}
       		var token = await CrossFirebaseCloudMessaging.Current.GetTokenAsync();
       		Console.WriteLine($"FCM Token: {token}");
       	}
       	catch (exception ex)
       	{
       		Console.WriteLine($"Token error: {ex.Message}");
       	}
       }
    
    Avoid calling it in the page constructor- instead trigger it:
    1. After the page loads, or
    2. After CheckIfValidAsync() returns true.

Why it worked with the demo JSON but fails now

The demo JSON and your production JSON belong to different Firebase projects.

After switching projects, the cached instanceID on the device no longer matches the project configuration, so FCM responds with:

SERVICE_NOT_AVAILABLE

Re-installing the app + downloading a new JSON resolves this in almost all cases.

Please let us know if you require any further assistance we’re happy to help. If you found this information useful, kindly mark this as "Accept Answer".

 

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.