aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.31k stars 240 forks source link

PushNotificationException "Error occurred awaiting for device token." #5119

Closed ClemPalf closed 1 week ago

ClemPalf commented 2 weeks ago

Description

Hi,

I am having trouble setting up push-notifications for android. I would suspect that the extra step I add to take (in addition to your documentation) to add the com.google.gms.google-services plugin is what is causing the error.

Regards,

Categories

Steps to Reproduce

I first encountered an issue at this stage : image Simply adding the line apply plugin: 'com.google.gms.google-services' to my app/build.gradle created the following error :

  • Where: Build file '/Users/clem/Documents/Morp/morp_alpha/android/app/build.gradle' line: 101

  • What went wrong: A problem occurred evaluating project ':app'.

    Plugin with id 'com.google.gms.google-services' not found.

I finally managed to compile the app by : 1) Adding this code snippet to my android/build.gradle file :

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.google.gms:google-services:4.4.2'
    }
}

2) Adding the google-services.json file provided by firebase in my android/app folder.

However, I now get the following runtime error when running Amplify.configure(amplifyconfig):

E/flutter ( 5262): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PushNotificationException { E/flutter ( 5262): "message": "Error occurred awaiting for device token.", E/flutter ( 5262): "recoverySuggestion": "Review the underlying exception.", E/flutter ( 5262): "underlyingException": "PlatformException(java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.morp.morp_alpha. Make sure to call FirebaseApp.initializeApp(Context) first., IllegalStateException, Cause: null, Stacktrace: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.morphit.morphit_alpha. Make sure to call FirebaseApp.initializeApp(Context) first.\n\tat com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:179)\n\tat com.google.firebase.messaging.FirebaseMessaging.getInstance(FirebaseMessaging.java:137)

Screenshots

No response

Platforms

Flutter Version

3.22.2

Amplify Flutter Version

2.2.0

Deployment Method

AWS CDK

Schema

No response

khatruong2009 commented 2 weeks ago

Hi @ClemPalf, thank you for submitting this issue. We will take a look at this issue and get back to you with any updates.

derrik-fleming commented 2 weeks ago

@ClemPalf try building using the version of com.google.gms:google-services that is used in the package's example app, here.

ClemPalf commented 1 week ago

It worked, thanks.

derrik-fleming commented 1 week ago

@khatruong2009 maybe worth still exploring why this error occurs with the latest com.google.gms:google-services, no? At the least, updating the docs to include the necessary latest compatible version.

khatruong2009 commented 1 week ago

Hi @derrik-fleming, thank you for mentioning this temporary fix for this issue. We'll look into this issue and update the docs in the mean time. Thank you.