7

I was trying to add push notification on react-native app, so I used react-native-push-notification. The library configuration went well, but when receiving notification the APP crashes immediately saying "FirebaseApp is not initialized".

Crash report AndroidRuntime: java.lang.IllegalStateException: Default FirebaseApp is not initialized in this com.myapp. Make sure to call FirebaseApp.initializeApp(Context) first.

How do I initialize the FirebaseApp or fix this problem? Any help will be greatly appreciated.

For more information there is an opened Github issue https://github.com/zo0r/react-native-push-notification/issues/852

ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56
sami
  • 231
  • 2
  • 8
  • 1
    Where exactly did you see this error "FirebaseApp is not initialized". My app is crashing, but I am not sure where to check the logs to figure out what is causing it> – JackDev Dec 18 '18 at 22:29

2 Answers2

10

OK! it works now.

build.gradle

buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:+'
    }
}

app/build.gradle

// At the very bottom of the file
apply plugin: 'com.google.gms.google-services'

Credit https://github.com/zo0r/react-native-push-notification/issues/852#issuecomment-417641675

sami
  • 231
  • 2
  • 8
  • 1
    not fixing the version of google-services can (and has for us) lead to problems in the future. Better fix the version like so: `classpath 'com.google.gms:google-services:4.2.0'` – David Schumann Nov 15 '19 at 14:26
0

It worked when i change my AndroidManifest.xml to

    <uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

<application ....>
    <!-- Change the value to true to enable pop-up for in foreground on receiving remote notifications (for prevent duplicating while showing local notifications set this to false) -->
    <meta-data  android:name="com.dieam.reactnativepushnotification.notification_foreground"
                android:value="false"/>
    <!-- Change the resource name to your App's accent color - or any other color you want -->
    <meta-data  android:name="com.dieam.reactnativepushnotification.notification_color"
                android:resource="@color/white"/> <!-- or @android:color/{name} to use a standard color -->

    <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" />
    <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
    <receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            <action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
        </intent-filter>
    </receiver>

    <service
        android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
        android:exported="false" >
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>
yash k
  • 1