ben-xD / push

Push notifications in Flutter without firebase_messaging.
https://pub.dev/packages/push
37 stars 22 forks source link

Error `Make sure to call FirebaseApp.initializeApp(Context) first.` #66

Open jvondermarck opened 1 month ago

jvondermarck commented 1 month ago
E/BasicMessageChannel#dev.flutter.pigeon.push_platform_interface.PushHostApi.getToken(27489): Failed to handle message
E/BasicMessageChannel#dev.flutter.pigeon.push_platform_interface.PushHostApi.getToken(27489): java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process <here my applicationID>. Make sure to call FirebaseApp.initializeApp(Context) first.
E/BasicMessageChannel#dev.flutter.pigeon.push_platform_interface.PushHostApi.getToken(27489):   at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:183)
E/BasicMessageChannel#dev.flutter.pigeon.push_platform_interface.PushHostApi.getToken(27489):   at com.google.firebase.messaging.FirebaseMessaging.getInstance(com.google.firebase:firebase-messaging@@23.0.0:1)
E/BasicMessageChannel#dev.flutter.pigeon.push_platform_interface.PushHostApi.getToken(27489):   at uk.orth.push.PushHostHandlers.getToken(PushHostHandlers.kt:52)
E/BasicMessageChannel#dev.flutter.pigeon.push_platform_interface.PushHostApi.getToken(27489):   at uk.orth.push.serialization.PushHostApi$Companion.setUp$lambda-3$lambda-2(PushApi.kt:340)
E/BasicMessageChannel#dev.flutter.pigeon.push_platform_interface.PushHostApi.getToken(27489):   at uk.orth.push.serialization.PushHostApi$Companion.$r8$lambda$DaI8nyMPCGeQZ28OWpPjC3ArNyU(Unknown Source:0)
E/BasicMessageChannel#dev.flutter.pigeon.push_platform_interface.PushHostApi.getToken(27489):   at uk.orth.push.serialization.PushHostApi$Companion$$ExternalSyntheticLambda1.onMessage(Unknown Source:2)
E/BasicMessageChannel#dev.flutter.pigeon.push_platform_interface.PushHostApi.getToken(27489):   at io.flutter.plugin.common.BasicMessageChannel$IncomingMessageHandler.onMessage(BasicMessageChannel.java:261)
E/BasicMessageChannel#dev.flutter.pigeon.push_platform_interface.PushHostApi.getToken(27489):   at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:292)

Why do I get the error when I run the code :

  void initPushNotification() async
  {
    Push.instance.requestPermission();

    pushToken = await Push.instance.token.then((value) {
      pushToken = value;
      debugPrint("Push token: $pushToken");
    }, onError: (error) {
      debugPrint("Error getting push token: $error");
    });
 }

In your example code, you did not do this "FirebaseApp.initializeApp(Context)" so that is weird...

ProfJackCZ commented 1 month ago

I've encountered the same issue. It looks related to the new com.google.gms:google-services version, which may have some breaking changes. A temporary solution that worked for me is using an older version of google services plugin. Try changing the version of com.google.gms.google-services to 4.3.15 in android/build.gradle

jvondermarck commented 1 month ago

Thank you @ProfJackCZ