Capacitor: Push plugin seems to work, but push notifications never arrive to any Android device

Created on 1 Jul 2020  Â·  10Comments  Â·  Source: ionic-team/capacitor

Bug Report

Capacitor Version

```
Capacitor Doctor

Latest Dependencies:

@capacitor/cli: 2.2.0

@capacitor/core: 2.2.0

@capacitor/android: 2.2.0

@capacitor/electron: 2.2.0

@capacitor/ios: 2.2.0

Installed Dependencies:

@capacitor/electron not installed

@capacitor/cli 2.2.0

@capacitor/android 2.2.0

@capacitor/core 2.2.0

@capacitor/ios 2.2.0

[success] Android looking great! �
[error] Xcode is not installed
```

Platform(s)

Android (didn't test iOS yet).

Current Behavior

Capacitor correctly installs into my project, and the PushNotifications plugin seems to work fine: it correctly gets a user token that also gets correctly stored in my backend. Thing is, when I send the actual push, it won't ever arrive to my device. Tested in two different devices (Xiaomi Pocophone F1, and a Huawei P Smart+).

Expected Behavior

These devices should be receiving the pushes correctly — which they don't.

Code Reproduction

I followed the Capacitor Push guidelines explained here and added them to my project. I created a service that has the exact same code that appears in this guide, and use it when a user logs into my platform. The registration listener works well and shows me that alert with the token, which is good, but I can't receive any pushes, both from my automated push server, or the Firebase Console. This is working exactly the same for both devices.

The same happens for a clean project, so it's not a problem in my side. I am suspicious that something "might" be wrong in the Firebase side, but I tried making a completely new Firebase project for this purpose, which won't work whatsoever.

Weird thing is that in the past I could get push notifications working from Cordova. They stopped working a couple of months ago, and after not being able to make this work with Cordova's plugins (and having tons of problems with Cordova), I decided to switch to Capacitor, which felt much better and with more concise explanations. I still think it was a good move, but I still don't understand why I am totally unable to make this work.

Things I tried:

  • Use a clean app.
  • Switch Firebase project and app, and therefore, use different google_services.json files.
  • Absolutely all the Firebase/Firebase-x plugins in Cordova.
  • Restart the Capacitor guide from 0, from a new project.
  • Using another phone (mine is the Xiaomi, but it works the same for the Huawei I mentioned.

Other Technical Details

npm --version output:
6.14.4

Additional Context

It's been a long time since I first tried to fix this weird day-to-day push failure, and this is starting to become a serious professional problem to me. I really have to finish the app I'm working with, and the main requisite is that push notifications work on it. This _may_ not be a Capacitor problem itself, but at this moment, I think I have isolated every possible problem that I could make in the process (either with my codebase or my tools), and this keeps doing the same: not working whatsoever.

So this is indeed a desperate call for help. I'll even consider paying you guys if you struggle finding the problem and fixing it, and will provide access to my repo if someone needs it (although, as I mentioned, it doesn't seem to have much to do with the project itself).

Thank you a lot for getting this far. Let's see if we're able to get this fixed!

android ios

Most helpful comment

Hello everyone, I fix my problem reading the firebase repo and please feel free to try if this can solve your problems with push notifications:

here is the source https://github.com/firebase/firebase-android-sdk/issues/1339

In my case the notification never arrived because the app crashes on background when I recive the message. this was a problem inside firebase-messaging:20.1.2 and is solved in 20.1.4

I did this to fix the problem:

change the version located in android/variables.gradle from 20.1.2 to 20.1.4

ext { minSdkVersion = 21 compileSdkVersion = 29 targetSdkVersion = 29 androidxAppCompatVersion = '1.1.0' androidxCoreVersion = '1.2.0' androidxMaterialVersion = '1.1.0-rc02' androidxBrowserVersion = '1.2.0' androidxLocalbroadcastmanagerVersion = '1.0.0' firebaseMessagingVersion = '20.1.4' playServicesLocationVersion = '17.0.0' junitVersion = '4.12' androidxJunitVersion = '1.1.1' androidxEspressoCoreVersion = '3.2.0' cordovaAndroidVersion = '7.0.0' }

Then in android studio go to "Files / Sync Project with Gradle Files", remove your app from your device, compile again and works very well on background.

I think the default version of firebase messaging will be updated on the next versions of capacitor, but that works for me.

This is only my case, please feel free to try and thank you for your comments.

All 10 comments

I am also having issues with push notifications via firebase. Odd thing for me is at times they go trough and other times they do not. Tried clean installs to no avail, im testing on iOS. I am receiving, and saving tokens.

It's weird that you receive some, and some not. I do not receive any notification whatsoever, but maybe our issues are somewhat related.

edit: anyways, I have to thank the Capacitor team for making plugin management easier than Cordova. Even if it's failing, it's been much easier to get to this point than with Cordova, which led me to many build errors.

I have the same issue, I reciving and storing tokens but when I send a message my app crash everytime and I don't see the pushnotification and I get this error, I have an app in capacitor 1.4 working very well, I started a clean project to test capacitor 2.2.1 and his benefits but the messages from firebase doesn't work for me, I think can be something related to firebase-messaging@@20.1.2:

````

2020-07-05 19:39:41.821 12465-12465/com.ottapp.app E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.ottapp.app, PID: 12465
java.lang.NoSuchMethodError: No static method zza()Lcom/google/firebase/iid/zzaz; in class Lcom/google/firebase/iid/zzaz; or its super classes (declaration of 'com.google.firebase.iid.zzaz' appears in /data/app/com.ottapp.app-xhxgJdHCusHgeaLbMwIwTw==/base.apk)
at com.google.firebase.messaging.FirebaseMessagingService.zza(com.google.firebase:firebase-messaging@@20.1.2:7)
at com.google.firebase.messaging.zzc.onStartCommand(com.google.firebase:firebase-messaging@@20.1.2:22)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4121)
at android.app.ActivityThread.access$1900(ActivityThread.java:220)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1915)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:224)
at android.app.ActivityThread.main(ActivityThread.java:7520)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

Xiaomi and Huawei are known to have some push notifications issues due to their memory management. I don't know if this is the case, but I think it's worth to take a look: https://www.androidcentral.com/how-fix-miui-push-notifications

Hello everyone, I fix my problem reading the firebase repo and please feel free to try if this can solve your problems with push notifications:

here is the source https://github.com/firebase/firebase-android-sdk/issues/1339

In my case the notification never arrived because the app crashes on background when I recive the message. this was a problem inside firebase-messaging:20.1.2 and is solved in 20.1.4

I did this to fix the problem:

change the version located in android/variables.gradle from 20.1.2 to 20.1.4

ext { minSdkVersion = 21 compileSdkVersion = 29 targetSdkVersion = 29 androidxAppCompatVersion = '1.1.0' androidxCoreVersion = '1.2.0' androidxMaterialVersion = '1.1.0-rc02' androidxBrowserVersion = '1.2.0' androidxLocalbroadcastmanagerVersion = '1.0.0' firebaseMessagingVersion = '20.1.4' playServicesLocationVersion = '17.0.0' junitVersion = '4.12' androidxJunitVersion = '1.1.1' androidxEspressoCoreVersion = '3.2.0' cordovaAndroidVersion = '7.0.0' }

Then in android studio go to "Files / Sync Project with Gradle Files", remove your app from your device, compile again and works very well on background.

I think the default version of firebase messaging will be updated on the next versions of capacitor, but that works for me.

This is only my case, please feel free to try and thank you for your comments.

Thanks @ivancduran this helped

Strange. Not for me... When the app is closed or in the background I don't receive any notifications. The notification received events in javascript work however (when the app is open)...

I had the same problem and solved it by https://github.com/ionic-team/capacitor/issues/3500#issuecomment-710129277

Hello everyone, I fix my problem reading the firebase repo and please feel free to try if this can solve your problems with push notifications:

here is the source firebase/firebase-android-sdk#1339

In my case the notification never arrived because the app crashes on background when I recive the message. this was a problem inside firebase-messaging:20.1.2 and is solved in 20.1.4

I did this to fix the problem:

change the version located in android/variables.gradle from 20.1.2 to 20.1.4

ext {
    minSdkVersion = 21
    compileSdkVersion = 29
    targetSdkVersion = 29
    androidxAppCompatVersion = '1.1.0'
    androidxCoreVersion =  '1.2.0'
    androidxMaterialVersion =  '1.1.0-rc02'
    androidxBrowserVersion =  '1.2.0'
    androidxLocalbroadcastmanagerVersion =  '1.0.0'
    firebaseMessagingVersion =  '20.1.4'
    playServicesLocationVersion =  '17.0.0'
    junitVersion =  '4.12'
    androidxJunitVersion =  '1.1.1'
    androidxEspressoCoreVersion =  '3.2.0'
    cordovaAndroidVersion =  '7.0.0'
}

Then in android studio go to "Files / Sync Project with Gradle Files", remove your app from your device, compile again and works very well on background.

I think the default version of firebase messaging will be updated on the next versions of capacitor, but that works for me.

This is only my case, please feel free to try and thank you for your comments.

Thanks!

Hello everyone, I fix my problem reading the firebase repo and please feel free to try if this can solve your problems with push notifications:

here is the source firebase/firebase-android-sdk#1339

In my case the notification never arrived because the app crashes on background when I recive the message. this was a problem inside firebase-messaging:20.1.2 and is solved in 20.1.4

I did this to fix the problem:

change the version located in android/variables.gradle from 20.1.2 to 20.1.4

ext {
    minSdkVersion = 21
    compileSdkVersion = 29
    targetSdkVersion = 29
    androidxAppCompatVersion = '1.1.0'
    androidxCoreVersion =  '1.2.0'
    androidxMaterialVersion =  '1.1.0-rc02'
    androidxBrowserVersion =  '1.2.0'
    androidxLocalbroadcastmanagerVersion =  '1.0.0'
    firebaseMessagingVersion =  '20.1.4'
    playServicesLocationVersion =  '17.0.0'
    junitVersion =  '4.12'
    androidxJunitVersion =  '1.1.1'
    androidxEspressoCoreVersion =  '3.2.0'
    cordovaAndroidVersion =  '7.0.0'
}

Then in android studio go to "Files / Sync Project with Gradle Files", remove your app from your device, compile again and works very well on background.

I think the default version of firebase messaging will be updated on the next versions of capacitor, but that works for me.

This is only my case, please feel free to try and thank you for your comments.

This solution worked for me but still the changes are not provided with capacitor latest updates in android.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bogdbo picture bogdbo  Â·  3Comments

json-derulo picture json-derulo  Â·  3Comments

daniel-lucas-silva picture daniel-lucas-silva  Â·  3Comments

gnesher picture gnesher  Â·  3Comments

json-derulo picture json-derulo  Â·  3Comments