7

我试图在 react-native 应用程序上添加推送通知,所以我使用了 react-native-push-notification。库配置进行得很顺利,但是当收到通知时,APP 立即崩溃,说“FirebaseApp 未初始化”。

崩溃报告 AndroidRuntime: java.lang.IllegalStateException: Default FirebaseApp 未在此 com.myapp 中初始化。确保首先调用 FirebaseApp.initializeApp(Context)。

如何初始化 FirebaseApp 或解决此问题?任何帮助将不胜感激。

有关更多信息,请参阅已打开的 Github 问题https://github.com/zo0r/react-native-push-notification/issues/852

4

2 回答 2

10

好的!现在可以了。

构建.gradle

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

应用程序/build.gradle

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

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

于 2018-09-01T13:32:09.790 回答
0

当我将我的 AndroidManifest.xml 更改为

    <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>
于 2021-11-17T09:56:11.407 回答