I am using react-native-notifications library to implement notification in my app with message cloud firebase , I have followed all guidelines in the documentation,
For react-native-notifications library
For firebase cloud messaging
So when I go to firebase counsel and send a test notification message, nothing happened the app just closed or could call it crash, I have added firebase-analytics
to help me with debug what the problem and this what I got when I sent test notification message:
Fatal Exception: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/common/util/zzq;
at com.google.android.gms.gcm.GcmReceiver.onReceive()
at android.app.ActivityThread.handleReceiver(ActivityThread.java:3177)
at android.app.ActivityThread.-wrap18(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1653)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:156)
at android.app.ActivityThread.main(ActivityThread.java:6523)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
here is my code:
import React from 'react'
import { Platform, View } from 'react-native'
import { Notifications } from 'react-native-notifications'
export default class PushNotificationManager extends React.Component {
componentDidMount() {
this.registerDevice()
this.registerNotificationEvents()
}
registerDevice = () => {
Notifications.events().registerRemoteNotificationsRegistered(event => {
// TODO: Send the token to my server so it could send back push notifications...
console.log('Device Token Received', event.deviceToken)
})
Notifications.events().registerRemoteNotificationsRegistrationFailed(event => {
console.error(event)
})
Notifications.registerRemoteNotifications()
}
registerNotificationEvents = () => {
Notifications.events().registerNotificationReceivedForeground((notification, completion) => {
console.log('Notification Received - Foreground', notification)
})
// Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
completion({ alert: false, sound: false, badge: false })
})
Notifications.events().registerNotificationOpened((notification, completion) => {
console.log('Notification opened by device user', notification)
console.log(`Notification opened with an action identifier: ${notification.identifier}`)
completion()
})
Notifications.events().registerNotificationReceivedBackground((notification, completion) => {
console.log('Notification Received - Background', notification)
// Calling completion on iOS with `alert: true` will present the native iOS inApp notification.
completion({ alert: true, sound: true, badge: false })
})
Notifications.getInitialNotification()
.then(notification => {
console.log('Initial notification was:', notification || 'N/A')
})
.catch(err => console.error('getInitialNotifiation() failed', err))
}
render() {
const { children } = this.props
return <View style={{ flex: 1 }}>{children}</View>
}
}
in console.log
it consoling the token and in
Notifications.getInitialNotification()
.then(notification => {
console.log('Initial notification was:', notification || 'N/A')
})
it keep consoling 'N/A'
and I wrapped the previous code with the whole app root:
<PaperProvider theme={theme}>
<AuthContext.Provider value={authContext}>
/* here*/ <PushNotificationManager>
<NavigationContainer theme={theme}>
<RootStackScreen />
</NavigationContainer>
/* here*/ </PushNotificationManager>
</AuthContext.Provider>
</PaperProvider>