Closed quocman1982 closed 3 years ago
I've just updated this module in an otherwise working project using an existing GCM key and also now get this error so I guess the recent PR that added Firebase Messaging may have broken GCM in some subtle way. I've not reviewed the new Android install instructions so it may be user error on my part.
Will investigate further this morning and try to fix locally in which case that may help you.
One thing I notice above is that you are using the Firebase Android Manifest lines, are you using a Firebase key and not a GCM key?
Dear rjp44,
Thank you for your reply, I sure I'm using Firebase Key. But the stranger thing is when I past the GCM Android Manifest lines in to Manifest file. In this case I did received notification and then it still crash (I'm not received notification if I just using Firebase Manifest lines) . Hope this help to debug.
OK, so I can solve the problem (for me), by backing out the change introduced in #717 (commit 44cb23006087bce22c0e7763c3598931d1aee14d ) to RNPushNotificationListnerService which starts deriving it from FireBaseListenerService.
I'm trying to use GCM in an existing project though, not Firebase so this probably won't help you as I guess it will further break attempts to use the Firebase API.
At the very least it seems like #717 breaks GCM, and may not work with Firebase either. I'm certainly not an expert on Google APIs but from 5 mins reading the code it seems to use the GCM calls to Register the ID, then use the FireBase Listener on it. Maybe that is an OK thing to do, but if I revert it at least GCM starts working again.
OK with me because I'm using react-native-fcm now hope this will fix soon.
@rjp44 So what did you change in the code exactly? I'm getting the same error.
I just backed out the edit to RNPushNotificationListenerService.java in the commit I reference above and changed the definition back to:
public class RNPushNotificationListenerService extends GcmListenerService
This got my GCM based project working again, but defeats that commit if you need Firebase.
I am also having this issue, exact same error logged. I'm using Firebase (with the GCM lines included in the manifest) and can get the notifications but they crash the app regardless if it is closed or not. The notification, however, remains in the tray and tapping it opens the app as expected.
When running my app on a HTC ( 'HTC 2PS6200 - 6.0.1') it all works fine. I get the above issue and don't receive any local notifications either when running Oreo on a Galaxy S7
compileSdkVersion = 26
targetSdkVersion = 26
buildToolsVersion = "26.0.2"
supportLibVersion = "26.1.0"
googlePlayServicesVersion = "11.8.0"
firebaseVer = "17.0.0"
UPDATE: Changing targetSdkVersion to 25 seems to have fixed this. I have successfully sent a message using FCM and I can get also localNotifications on both phones. I have react-native-push-notification@3.0.2 installed.
here is my full AndroidManifest.xml in case it helps.
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.locationnotification">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="itp-qld"/>
<!-- <Only if you're using GCM> -->
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission
android:name="${applicationId}.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
<!-- </Only if you're using GCM> -->
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:theme="@style/AppTheme">
<!-- <Only if you're using GCM> -->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
<!-- </Only if you're using GCM> -->
<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" />
</intent-filter>
</receiver>
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>
<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
android:exported="false" >
<intent-filter>
<!-- <Only if you're using GCM> -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<!-- </Only if you're using GCM> -->
<!-- <Else> -->
<action android:name="com.google.firebase.MESSAGING_EVENT" />
<!-- </Else> -->
</intent-filter>
</service>
<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<!-- react-native-background-geolocation licence -->
<meta-data android:name="com.transistorsoft.locationmanager.license" android:value="YOUR_LICENCE_KEY_HERE" />
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
Dropping back to API 25 isn't really a solution for most folks, especially as Google won't be accepting new app submissions with API < 26 from 1st August (tomorrow!).
Looks like 3.1.1 has been pushed to npm with this crasher bug in it.
Hello guys, Can you try with the master branch of this repo ? We merged some code for FCM support, maybe it solves the issue ?
@Gp2mv3 Perhaps I'm wrong because I tested in an emulator, but here is what I see with adb logcat when I send a notification. Hope it can help
adb logcat:
08-02 13:17:39.306 4909 4909 D AndroidRuntime: Shutting down VM
08-02 13:17:39.307 4909 4909 E AndroidRuntime: FATAL EXCEPTION: main
08-02 13:17:39.307 4909 4909 E AndroidRuntime: Process: com.merchantapp, PID: 4909
08-02 13:17:39.307 4909 4909 E AndroidRuntime: java.lang.ClassCastException: com.google.firebase.iid.zzf cannot be cast to com.google.android.gms.iid.zzi
08-02 13:17:39.307 4909 4909 E AndroidRuntime: at com.google.android.gms.iid.zzk.onServiceConnected(Unknown Source:4)
08-02 13:17:39.307 4909 4909 E AndroidRuntime: at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1634)
08-02 13:17:39.307 4909 4909 E AndroidRuntime: at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1663)
08-02 13:17:39.307 4909 4909 E AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:789)
08-02 13:17:39.307 4909 4909 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:98)
08-02 13:17:39.307 4909 4909 E AndroidRuntime: at android.os.Looper.loop(Looper.java:164)
08-02 13:17:39.307 4909 4909 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6541)
08-02 13:17:39.307 4909 4909 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
08-02 13:17:39.307 4909 4909 E AndroidRuntime: at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
08-02 13:17:39.307 4909 4909 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
08-02 13:17:39.308 1658 2369 W ActivityManager: Force finishing activity com.merchantapp/.MainActivity
package.json:
"dependencies": {
...
"react": "16.4.1",
"react-native": "0.56.0",
"react-native-push-notification": "github:zo0r/react-native-push-notification#master",
...
}
UPDATE:
After reading https://developers.google.com/cloud-messaging/android/android-migrate-fcm I delete all <!-- <Only if you're using GCM> -->
in AndroidManifest and set firebaseVersion = "17.0.0", but I got this error:
08-03 11:35:59.872 8843 8941 W FirebaseMessaging: Error while parsing timestamp in GCM event
08-03 11:35:59.872 8843 8941 W FirebaseMessaging: java.lang.NumberFormatException: s == null
08-03 11:35:59.872 8843 8941 W FirebaseMessaging: at java.lang.Integer.parseInt(Integer.java:570)
08-03 11:35:59.872 8843 8941 W FirebaseMessaging: at java.lang.Integer.parseInt(Integer.java:643)
08-03 11:35:59.872 8843 8941 W FirebaseMessaging: at com.google.firebase.messaging.zzb.zzb(Unknown Source:79)
08-03 11:35:59.872 8843 8941 W FirebaseMessaging: at com.google.firebase.messaging.zzb.zzc(Unknown Source:2)
08-03 11:35:59.872 8843 8941 W FirebaseMessaging: at com.google.firebase.messaging.FirebaseMessagingService.zzd(Unknown Source:328)
08-03 11:35:59.872 8843 8941 W FirebaseMessaging: at com.google.firebase.iid.zzg.run(Unknown Source:26)
08-03 11:35:59.872 8843 8941 W FirebaseMessaging: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
08-03 11:35:59.872 8843 8941 W FirebaseMessaging: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
08-03 11:35:59.872 8843 8941 W FirebaseMessaging: at com.google.android.gms.common.util.concurrent.zza.run(Unknown Source:7)
08-03 11:35:59.872 8843 8941 W FirebaseMessaging: at java.lang.Thread.run(Thread.java:764)
08-03 11:35:59.875 8843 8941 E AndroidRuntime: FATAL EXCEPTION: Firebase-RNPushNotificationListenerService
Looking in Stackoverflow I found this: https://stackoverflow.com/questions/50819595/error-when-push-notification-by-postman-but-not-when-send-by-firebase-console?noredirect=1&lq=1
A comment said: This is a known issue but should not affect your application in anyway other than the warning message in the log. The FCM team is looking into it
, so I set firebaseVersion = "15.0.0" and it works 😬!
UPDATE 2: I noticed that app is crashing if I send from server notification field (nodejs and firebase-admin). Tested with firebaseVersion 17.1.0 and react-native-push-notification: 3.1.1.
Change:
{
token: registrationToken,
notification: {
title: '$GOOG up 1.43% on the day',
body: '$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.',
},
data: {
hello: 'world',
},
};
To:
{
token: registrationToken,
data: {
hello: 'world',
notification: JSON.stringify({
title: '$GOOG up 1.43% on the day',
body: '$GOOG gained 11.80 points to close at 835.67, up 1.43% on the day.',
}),
},
};
3.1.1 I have same issue with remote notifications. Local notifs seem to work fine:
--------- beginning of crash
08-02 23:31:34.806 3098-3098/com.mycompany E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mycompany, PID: 3098
java.lang.ClassCastException: com.google.firebase.iid.zzf cannot be cast to com.google.android.gms.iid.zzi
at com.google.android.gms.iid.zzk.onServiceConnected(Unknown Source:4)
at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1730)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1762)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Please note, I still use old GCM messaging.
I have tried both react-native-push-notification 3.1.1 from npm library and also to target package.json against the master branch on this repo. Same result.
Crashes with the result below:
java.lang.ClassCastException: com.google.firebase.iid.zzf cannot be cast to com.google.android.gms.iid.zzi
android.app.LoadedApk$ServiceDispatcher.doConnected LoadedApk.java:1691
android.app.LoadedApk$ServiceDispatcher$RunConnection.run LoadedApk.java:1720
android.os.Handler.handleCallback Handler.java:790
android.os.Handler.dispatchMessage Handler.java:99
android.os.Looper.loop Looper.java:164
android.app.ActivityThread.main ActivityThread.java:6753
java.lang.reflect.Method.invoke Method.java
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run RuntimeInit.java:482
com.android.internal.os.ZygoteInit.main ZygoteInit.java:807
Configuration: targetSdkVersion 26 compileSdkVersion 27 buildToolsVersion "27.0.3" react-native: 0.55.4 react-native-push-notification: 3.1.1 Android version: 8.1.0
EDIT: I tried @giankotarola solution and set fireBase version to 15.0.0 in build.gradle. Now remote notifications works, the app does not crash, but local notifications does not work.
@hanssonfredrik Have you try with react-native: 0.56.0??
I don't have any problems with this config:
targetSdkVersion 26
compileSdkVersion 26
buildToolsVersion "26.0.3"
react-native: 0.56.0
react-native-push-notification: 3.1.1
Android version: 8.0 / 8.1
@giankotarola could you please show us your package.json and compile gradle compile section
@andrei-m-code Sure!
package.json:
{
......
"dependencies": {
.....
"react": "16.4.1",
"react-native": "0.56.0",
"react-native-push-notification": "^3.1.1",
......
},
......
}
build.gradle:
ext {
firebaseVersion = "17.1.0"
buildToolsVersion = "26.0.3"
minSdkVersion = 16
compileSdkVersion = 26
targetSdkVersion = 26
supportLibVersion = "26.1.0"
}
AndroidManifest.xml:
<manifest ...>
.....
<application ...>
.....
<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" />
</intent-filter>
</receiver>
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>
<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
.....
</application>
</manifest>
@andrei-m-code did @giankotarola configuration solve this problem?
@n1ru4l it did. My problem was in the version upgrade. I had to swap gcm with fcm in manifest which I initially didn't do and for obvious reasons was getting errors. I guess for ppl starting from scratch it will work right away. It's just for those who upgrade from earlier version they need to make manifest changes - which wasn't written anywhere, or I didn't see it.
Yeah I had this and my issue was that I also had the GCM config in my manifest
Can we say this issue is solved with the right configuration files then ?
@Gp2mv3 Yeah, this issue is solved. However there are still some issues with the fcm integration. E.g. the onNotification
handler does not receive the message object.
Only if you are using Firebase! Existing GCM based applications were broken when PR #717 was merged and anything since appears to register etc but then crashes when a GCM notification is received as far as I can tell. I guess that is kind of OK if the documentation flagged a breaking change and said clearly "GCM not supported anymore" by removing all references to GCM in documentation and code.
I just created a PR (#835) for GCM back-compatibility do you think we can merge something similar ?
Not sure that PR will work exactly, and also don't have time to test/debug it until next week, distracted by a different project but from a quick scan, I think the class name needs to be RNPushNotificationListenerService not RNPushNotificationListenerServiceGcm. My Java is very very rusty but suspect the FCM and GCM variant need wrapping in an abstract class named RNPushNotificationListenerService. Maybe that way we can also avoid the cut and paste code replication. Will look at this by the end of next week and propose something.
Removing the GCM lines at AndroidManifest.xml fixed my problem. Thanks @giankotarola
@GabeConsalter Please tell which line you delete in AndroidManifest.xml? I am also facing this issue.
@uzairkhan01 I had some GCM lines because I've tried to set up the GCM configuration but I change to FCM configuration. So I removed this lines from AndroidManifest.xml:
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="<PACKAGE_NAME>" />
</intent-filter>
</receiver>
Thanks @GabeConsalter It works. It will also work for GCM ?
For me, no one GCM config worked @uzairkhan01. It seems that it's better forget the GCM and change to FCM configs.
If you are using GCM, please make sure that you are using RNPushNotificationListenerServiceGcm
in AndroidManifest.xml
:
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerServiceGcm" android:exported="false" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> </intent-filter> </service>
Not RNPushNotificationListenerService
, that was used on previous versions.
@nartjie101 worked for me. Thanks!
I am testing with FCM and removed all GCM references from AndroidManifest.xml
, the app is still crashing when a notification is sent. @GabeConsalter can you share your config?
Sure @StijnCoolen! Here is the FCM config lines from my AndroidManifest.xml
.
I'm using react-native-fcm
and react-native-push-notification
.
<application
...
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@mipmap/ic_notification"/>
<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="my_default_channel"/>
<service android:name="com.evollu.react.fcm.MessagingService" android:enabled="true" android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service android:name="com.evollu.react.fcm.InstanceIdService" android:exported="false">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
...
<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" />
</intent-filter>
</receiver>
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>
<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
...
</application>
@GabeConsalter thank you! Although I wonder why I should use react-native-fcm
? It feels strange to use 2 libraries that essentially are both doing the same thing. Also shouldn't you be able to use react-native-push-notification
to receive FCM notifications without adding another library?
@StijnCoolen yes! I had problems to set PushNotifications on Android. I am using react-native-push-notification
to both platforms (iOS & Android). In iOS everything works fine with just this library and the APNS service. To Android platform this library helps me to request permissions and other configs, but, the notification still to not appears. I searched for alternatives and see that react-native-fcm
helps me with receivers to notifications and another features in Android code that makes my push notification work. So, I chose to keep both libraries.
If you got this error in android Logcat with no filter:
java.lang.RuntimeException: Unable to instantiate service com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerServiceGcm:
java.lang.ClassNotFoundException: Didn't find class "com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerServiceGcm"
use FCM service instead of GCM service in AndroidManifest.xml:
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
"react-native": "0.57.7"
"react-native-push-notification": "3.1.2"
"node-gcm": "1.0.2"
project/android/build.gradle
:
buildscript {
...
dependencies {
...
classpath 'com.google.gms:google-services:+'
}
}
...
project/android/app/build.gradle
:
...
apply plugin: 'com.google.gms.google-services'
Android Manifest
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="bundleID">
...
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:name=".MainApplication"
...
>
<activity
android:name=".MainActivity"
...
>
...
<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" />
</intent-filter>
</receiver>
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>
<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
</application>
</manifest>
https://console.firebase.google.com/project/projectID/settings/general/android:bundleID
Download the latest config file google-services.json
and place it in:
project/android/app/google-services.json
Use Sender ID from https://console.firebase.google.com/project/projectID/settings/cloudmessaging/
PushNotification.configure({
senderID: <Sender ID>
})
Use Legacy server key
form https://console.firebase.google.com/project/projectID/settings/cloudmessaging/
export const gcmProviderCreator = () => {
return new gcm.Sender(<Legacy server key>)
}
I have updated to 3.1.2 and it no longer crashes, but localNotifications stopped working. On 3.1.1 localNotifications work, but push notifications crashes. I don't know what to do...
@atulmy any ideas on that? It crashes when I use GCM...
@GabeConsalter how to change from GCM to Firebase?
@nartjie101 I am using version 3.1.1 and I have tried both RNPushNotificationListenerServiceGcm
and RNPushNotificationListenerService
and the app crashes on both cases. With 3.1.2 version the app does not crash but localNotifications don't work. Any suggested solution?
Ok, sorry for the flood, but I have just found a solution and I would like to share it with you. I am on v3.1.1 and I migrated GCM to FCM. For FCM migration I needed to read the guides from Firebase.
Maybe we should add to the Readme file of this repo?
The main difference is that on android/app/build.gradle
we have to change this line:
implementation 'com.google.firebase:firebase-core:16.0.6'
Before implementation line was with GCM instead of firebase. Also at the end of gradle file:
apply plugin: 'com.google.gms.google-services'
And voila. It works great.
@pedrosimao your hint with reading the RN firebase docs helped me a lot, thanks!
@jneuendorf You are welcome. I am glad I could be of some help!
i have been stucking on thi issue from the whole day.
02-18 16:14:01.881 14862-15036/? E/AndroidRuntime: FATAL EXCEPTION: Firebase-RNPushNotificationListenerService Process: com.goldspring, PID: 14862 java.lang.AbstractMethodError: abstract method "void com.google.firebase.iid.zzb.zzd(android.content.Intent)" at com.google.firebase.iid.zzg.run(Unknown Source:26) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at com.google.android.gms.common.util.concurrent.zza.run(Unknown Source:6) at java.lang.Thread.run(Thread.java:764)
i am using react-native-push-notification. i am using firebasevserion:"+". my Manifest file is:
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name"
android:value="YOUR NOTIFICATION CHANNEL NAME"/>
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description"
android:value="YOUR NOTIFICATION CHANNEL DESCRIPTION"/>
<!-- 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="@android:color/white"/>
<!-- < Only if you're using GCM or localNotificationSchedule() > -->
<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" />
</intent-filter>
</receiver>
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>
<!-- < Only if you're using GCM or localNotificationSchedule() > -->
<!-- </ Only if you're using GCM or localNotificationSchedule() > -->
<!-- < Else > -->
<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
I still get crash on notification received.
android/app/gradle
` android {
compileSdkVersion 28
buildToolsVersion '28.0.0'
defaultConfig {
applicationId "com.XXX"
minSdkVersion 16
targetSdkVersion 28
versionCode 013
versionName "XXXX"
multiDexEnabled true
ndk {
abiFilters "armeabi-v7a", "x86"
}
manifestPlaceholders = [manifestApplicationId: "${applicationId}",
onesignal_app_id: "XXX",
onesignal_google_project_number: "XXX"]
}
packagingOptions { pickFirst 'lib/x86/libc++_shared.so' pickFirst 'lib/x86_64/libjsc.so' pickFirst 'lib/arm64-v8a/libjsc.so' pickFirst 'lib/arm64-v8a/libc++_shared.so' pickFirst 'lib/x86_64/libc++_shared.so' pickFirst 'lib/armeabi-v7a/libc++_shared.so' }
signingConfigs {
debug {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
splits {
abi {
reset()
enable enableSeparateBuildPerCPUArchitecture
universalApk false // If true, also generate a universal APK
include "armeabi-v7a", "x86"
}
}
buildTypes {
release {
manifestPlaceholders = [isDebug:false]
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
// added on 2/6/2019
debug {
manifestPlaceholders = [isDebug:true]
}
}
// applicationVariants are e.g. debug, release
applicationVariants.all { variant ->
variant.outputs.each { output ->
// For each separate APK per architecture, set a unique version code as described here:
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
def versionCodes = ["armeabi-v7a":1, "x86":2]
def abi = output.getFilter(OutputFile.ABI)
if (abi != null) { // null for the universal-debug, universal-release variants
output.versionCodeOverride =
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
}
}
}
// packagingOptions { // pickFirst '**/libjsc.so' // } }
dependencies { compile project(':react-native-gesture-handler') compile project(':react-native-push-notification') implementation fileTree(dir: "libs", include: ["*.jar"]) implementation "com.android.support:appcompat-v7:28.0.0" compile "com.android.support:support-core-utils:28.0.0" implementation project(':react-native-fcm') implementation 'com.google.firebase:firebase-core:16.0.8' implementation 'com.google.firebase:firebase-messaging:17.6.0' implementation ("com.facebook.react:react-native:+") { force = true } // From node_modules implementation project(':realm') implementation project(':react-native-fs') implementation project(':react-native-vector-icons') implementation project(':react-native-image-picker') implementation project(':react-native-fetch-blob') implementation project(':react-native-image-crop-picker') implementation project(':react-native-exit-app') implementation project(':react-native-onesignal') implementation project(':react-native-sensor-manager') implementation project(':react-native-smart-barcode') implementation project(':react-native-push-notification') implementation project(':react-native-linear-gradient') implementation project(':react-native-file-picker') implementation project(':react-native-doc-viewer') implementation project(':react-native-svg') implementation project(":react-native-google-signin") implementation project(':react-native-spinkit') implementation project(':react-native-pdf') }
task copyDownloadableDepsToLibs(type: Copy) { from configurations.compile into 'libs' }
configurations.all { resolutionStrategy.eachDependency { DependencyResolveDetails details -> def requested = details.requested if (requested.group == 'com.android.support') { if (!requested.name.startsWith("multidex")) { details.useVersion '25.3.1' } } } }
apply plugin: 'com.google.gms.google-services' `
build/gradle
`buildscript { ext { // googlePlayServicesAuthVersion = "15.0.1" // <--- use this version or newer firebaseVersion ="16.0.6" buildToolsVersion = "28.0.3" minSdkVersion = 16 compileSdkVersion = 28 targetSdkVersion = 28 supportLibVersion = "28.0.0" } repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.3.1' classpath 'com.google.gms:google-services:+'
}
}
allprojects { repositories { google() mavenLocal() mavenLocal() // for modules depending on jitpack.io maven { url "https://jitpack.io" } // add this one maven { url "https://maven.google.com" } maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url "$rootDir/../node_modules/react-native/android" // url 'https://maven.google.com' } jcenter() } }
subprojects { afterEvaluate {project -> if (project.hasProperty("android")) { android { compileSdkVersion 28 buildToolsVersion "28.0.0" defaultConfig { targetSdkVersion 28 } } } } } `
AndroidManifest
` <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.xxxxx" android:versionCode="0.1.1" android:versionName="xxx">
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission
android:name="${applicationId}.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="${applicationId}.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-feature android:name="android.hardware.camera" android:required="true"/>
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="28" />
<application
android:name=".MainApplication"
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme"
android:launchMode="singleTop" >
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name"
android:value="YOUR NOTIFICATION CHANNEL NAME"/>
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description"
android:value="YOUR NOTIFICATION CHANNEL DESCRIPTION"/>
<!-- 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="@android:color/white"/>
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
<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" />
</intent-filter>
</receiver>
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>
<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustResize"
android:screenOrientation="portrait"
>
</activity>
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
</application>
`
@uendar
can you please tell me which version of react-native-push-notification you are using?
If you got this error in android Logcat with no filter:
java.lang.RuntimeException: Unable to instantiate service com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerServiceGcm: java.lang.ClassNotFoundException: Didn't find class "com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerServiceGcm"
use FCM service instead of GCM service in AndroidManifest.xml:
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService" android:exported="false" > <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service>
Hi has anyone found a solution to the issue outlined by @Husseinhj ? We are getting the same issue. react-native: 0.61.2 react-native-push-notification: 3.1.9
Check if you're using
classpath 'com.google.gms:google-services:4.1.0'
This one has the problem. Either upgrade it or downgrade to 4.0.0
. This fixed issue for me.
package.json:
build.gradle:
android/app/build.gradle:
AndroidManifest.xml:
<application ...>
<activity .......
android:launchMode="singleTop">
.........
</activity>
<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" />
</intent-filter>
</receiver>
<service android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationRegistrationService"/>
<service
android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
.....
</application>
I got it fixed in my code. For me, I had copied extra piece of code in AndroidManifest.xml that was only needed for gcm.
removing that code works fine for me
Everything working until it receive an notification
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.seller, PID: 15468 java.lang.ClassCastException: com.google.android.gms.iid.zzi cannot be cast to com.google.firebase.iid.zzf at com.google.firebase.iid.zzh.onServiceConnected(Unknown Source:4) at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1730) at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1762) at android.os.Handler.handleCallback(Handler.java:873) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:193) at android.app.ActivityThread.main(ActivityThread.java:6669) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.seller">
Can you help me ?