Firebase messaging error fix

Создано: 8 января 2025 г.

Отвечено с использованием OpenAI 01 от OpenAI01

Вопрос

Restarted application in 2,379ms.
I/FLTFireMsgService( 5489): FlutterFirebaseMessagingBackgroundService started!
D/FRCPlugin( 5489): Sending fetchTimeout: 5
W/FLTFireMsgService( 5489): Attempted to start a duplicate background isolate. Returning...
E/FirebaseMessaging( 5489): Failed to get FIS auth token
E/FirebaseMessaging( 5489): java.util.concurrent.ExecutionException: com.google.firebase.installations.FirebaseInstallationsException: Firebase Installations Service is unavailable. Please try again later.
E/FirebaseMessaging( 5489): at com.google.android.gms.tasks.Tasks.zza(com.google.android.gms:play-services-tasks@@18.1.0:5)
E/FirebaseMessaging( 5489): at com.google.android.gms.tasks.Tasks.await(com.google.android.gms:play-services-tasks@@18.1.0:9)
E/FirebaseMessaging( 5489): at com.google.firebase.messaging.GmsRpc.setDefaultAttributesToBundle(GmsRpc.java:283)
E/FirebaseMessaging( 5489): at com.google.firebase.messaging.GmsRpc.startRpc(GmsRpc.java:245)
E/FirebaseMessaging( 5489): at com.google.firebase.messaging.GmsRpc.getToken(GmsRpc.java:195)
E/FirebaseMessaging( 5489): at com.google.firebase.messaging.FirebaseMessaging.lambda$blockingGetToken$14$com-google-firebase-messaging-FirebaseMessaging(FirebaseMessaging.java:650)
E/FirebaseMessaging( 5489): at com.google.firebase.messaging.FirebaseMessaging$$ExternalSyntheticLambda8.start(Unknown Source:6)
E/FirebaseMessaging( 5489): at com.google.firebase.messaging.RequestDeduplicator.getOrStartGetTokenRequest(RequestDeduplicator.java:67)
E/FirebaseMessaging( 5489): at com.google.firebase.messaging.FirebaseMessaging.blockingGetToken(FirebaseMessaging.java:646)
E/FirebaseMessaging( 5489): at com.google.firebase.messaging.FirebaseMessaging.lambda$getToken$7$com-google-firebase-messaging-FirebaseMessaging(FirebaseMessaging.java:420)
E/FirebaseMessaging( 5489): at com.google.firebase.messaging.FirebaseMessaging$$ExternalSyntheticLambda4.run(Unknown Source:4)
E/FirebaseMessaging( 5489): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:487)
E/FirebaseMessaging( 5489): at java.util.concurrent.FutureTask.run(FutureTask.java:264)
E/FirebaseMessaging( 5489): at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:307)
E/FirebaseMessaging( 5489): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
E/FirebaseMessaging( 5489): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
E/FirebaseMessaging( 5489): at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement@@18.3.0:2)
E/FirebaseMessaging( 5489): at java.lang.Thread.run(Thread.java:1012)
E/FirebaseMessaging( 5489): Caused by: com.google.firebase.installations.FirebaseInstallationsException: Firebase Installations Service is unavailable. Please try again later.
E/FirebaseMessaging( 5489): at com.google.firebase.installations.remote.FirebaseInstallationServiceClient.createFirebaseInstallation(FirebaseInstallationServiceClient.java:154)
E/FirebaseMessaging( 5489): at com.google.firebase.installations.FirebaseInstallations.registerFidWithServer(FirebaseInstallations.java:533)
E/FirebaseMessaging( 5489): at com.google.firebase.installations.FirebaseInstallations.doNetworkCallIfNecessary(FirebaseInstallations.java:387)
E/FirebaseMessaging( 5489): at com.google.firebase.installations.FirebaseInstallations.lambda$doRegistrationOrRefresh$3$com-google-firebase-installations-FirebaseInstallations(FirebaseInstallations.java:372)
E/FirebaseMessaging( 5489): at com.google.firebase.installations.FirebaseInstallations$$ExternalSyntheticLambda0.run(Unknown Source:4)
E/FirebaseMessaging( 5489): at com.google.firebase.concurrent.SequentialExecutor$1.run(SequentialExecutor.java:117)
E/FirebaseMessaging( 5489): at com.google.firebase.concurrent.SequentialExecutor$QueueWorker.workOnQueue(SequentialExecutor.java:229)
E/FirebaseMessaging( 5489): at com.google.firebase.concurrent.SequentialExecutor$QueueWorker.run(SequentialExecutor.java:174)
E/FirebaseMessaging( 5489): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
E/FirebaseMessaging( 5489): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
E/FirebaseMessaging( 5489): at com.google.firebase.concurrent.CustomThreadFactory.lambda$newThread$0$com-google-firebase-concurrent-CustomThreadFactory(CustomThreadFactory.java:47)
E/FirebaseMessaging( 5489): at com.google.firebase.concurrent.CustomThreadFactory$$ExternalSyntheticLambda0.run(Unknown Source:4)
E/FirebaseMessaging( 5489): ... 1 more
D/FRCPlugin( 5489): Sending fetchTimeout: 5
I/flutter ( 5489): ----------------FIREBASE CRASHLYTICS----------------
I/flutter ( 5489): PlatformException(firebase_remote_config, Unable to connect to the server. Check your connection and try again., null, null)
I/flutter ( 5489):
I/flutter ( 5489): ----------------------------------------------------
I/flutter ( 5489): ----------------FIREBASE CRASHLYTICS----------------
I/flutter ( 5489): MissingPluginException(No implementation found for method setAccelerationSamplingPeriod on channel dev.fluttercommunity.plus/sensors/method)
I/flutter ( 5489): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:332:7)
I/flutter ( 5489): <asynchronous suspension>
I/flutter ( 5489): ----------------------------------------------------
D/FRCPlugin( 5489): Sending fetchTimeout: 5

Мысль

Identifying potential causes

I'm piecing together the log entries, highlighting potential issues with Flutter Firebase, including a known bug, Firebase Installations, and connectivity problems.

Investigating potential issues

I’m thinking about the cause of the error, which could be device settings, invalid google-services.json, dependency mismatch, old app version, network connectivity, or firewall issues.

Thought about Firebase messaging error cho 23 giây

Ответ

Here are some pointers for troubleshooting the log messages and errors you’re seeing. They fall roughly into three categories:

  1. Firebase Installations & Messaging Errors
  2. Remote Config Connection Issues
  3. Missing Plugin for Sensors

Below are step-by-step suggestions that may help isolate and fix each issue.


1. Firebase Installations & Messaging Errors

You’re seeing:

E/FirebaseMessaging(5489): Failed to get FIS auth token
E/FirebaseMessaging(5489): FirebaseInstallationsException: Firebase Installations Service is unavailable. Please try again later.

This usually indicates that something is preventing Firebase from retrieving a valid installation token. Common causes include:

  • Incorrect or Missing google-services.json
    Make sure that your Android app’s google-services.json file is present in the correct folder (android/app/) and that it matches the package name in your app/build.gradle.

  • Dependency or Version Mismatch
    Check your Gradle dependencies for Firebase and ensure they align with the versions recommended by the Firebase docs. Having conflicting or outdated dependencies can cause installation errors. Also verify your Gradle plugin versions in android/build.gradle and android/gradle.properties.

  • Network or Proxy Issues
    Sometimes local network restrictions, flaky connections, or proxy settings block requests to Firebase services. Verify that you have stable connectivity, and try testing on a different network or device.

  • Multiple Firebase App Instances
    If you’re using multiple Firebase apps or have tried to initialize Firebase more than once, it can cause unexpected behavior. Make sure you call Firebase.initializeApp() only once in the Dart side, and ensure your application class in native Android is not duplicating initialization.

  • Duplicate Background Isolate
    The warning:

    W/FLTFireMsgService(5489): Attempted to start a duplicate background isolate.
    

    is typically harmless in debugging. It means Flutter tried to spin up multiple background isolates for messaging. Usually it’s not critical, but if you see side effects, refer to the official FlutterFire documentation about background messaging setup.


2. Remote Config Connection Issues

You also have:

PlatformException(firebase_remote_config, Unable to connect to the server. Check your connection and try again., null, null)

When Firebase Remote Config reports it can’t connect, possible issues include:

  • No Network or Very Slow Connection
    Double-check network connectivity on the device or emulator.

  • Region or Firewall Restrictions
    Some networks block certain ports or Google endpoints. If you’re on a restricted Wi-Fi or corporate network, you might need to whitelist certain addresses or try another network.

  • Incorrect or Outdated Dependencies
    Like with Firebase Installations, check if your Remote Config version matches your other Firebase plugin versions in pubspec.yaml and in the Android Gradle files.

  • App Hasn’t Been Configured Properly
    Ensure that you’ve called RemoteConfig.instance.fetchAndActivate() (or whichever method you’re using) at the right place in your code and are waiting for completion. If you’re trying to do so too early (i.e., before Firebase.initializeApp() has completed), you can hit errors.


3. Missing Plugin for Sensors

You have a separate error:

MissingPluginException(No implementation found for method setAccelerationSamplingPeriod on channel dev.fluttercommunity.plus/sensors/method)

This generally means that the native (Android or iOS) side doesn’t have a matching implementation for the Dart method you’re calling. Potential fixes:

  • Check Your Plugin Versions
    If you’re using something like sensors_plus or another sensor-related package, ensure you’ve updated both the plugin and your app’s dependencies. Certain method calls may have been removed, renamed, or not yet implemented on some platforms.

  • Rebuild / Clean the Project
    After changing plugin versions, do a clean rebuild:

    flutter clean flutter pub get flutter run

    Sometimes Flutter doesn’t pick up new method channels until after a clean build.

  • Confirm the Plugin Actually Exposes That Method
    Look at the plugin’s docs (or code) to see if setAccelerationSamplingPeriod is still supported. If not, you may need to update your usage or switch to a supported method.


Additional Tips

  1. Check Your pubspec.yaml
    Make sure all Flutter plugins and Firebase packages are at compatible versions. Using the flutter pub outdated command can help you see if there are newer, compatible versions.

  2. Validate Android Setup

    • In your android/build.gradle (project-level), confirm you have:
      buildscript { dependencies { classpath 'com.android.tools.build:gradle:X.X.X' classpath 'com.google.gms:google-services:4.3.X' } }
    • In your android/app/build.gradle, confirm at the bottom:
      apply plugin: 'com.google.gms.google-services'
  3. Upgrade Gradle & Flutter
    Make sure you’re on a recent version of Flutter and Gradle. Old Gradle plugin versions can interfere with new Firebase SDKs. A typical recent setup:

    buildscript { repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:8.0.2' classpath 'com.google.gms:google-services:4.3.15' } }
  4. Check Official Docs
    If in doubt, compare your setup with the official FlutterFire documentation:


Summary

  • Firebase Installations/Messaging: Verify google-services.json, dependencies, network connectivity, and initialization routines.
  • Remote Config: Confirm network, plugin version matching, and that your code calls fetchAndActivate() after Firebase is initialized.
  • Sensors MissingPluginException: Ensure the plugin you’re using actually provides setAccelerationSamplingPeriod, that it’s the latest version, and that you’ve rebuilt cleanly.

Walking through these steps often resolves these errors. If issues persist, you can enable extra logging in your Gradle build or via flutter run -v to see more details.

Поделиться этим Q&A