Closed mvaljento closed 1 year ago
An update: I finally got it working by adding the following to beginning of the android/build.gradle file:
apply plugin: 'com.google.gms.google-services'
Also I needed to manually copy the google-services.json file to the android/app folder.
I guess something in the installation or build process of the plugin is not working properly?
Hey @mvaljento i also faced the same issue, Thanks for opening it also thanks for providing the solution 👍
copying the google-services.json
to android/app
folder is the only step needed, it's documented here
the apply plugin: 'com.google.gms.google-services'
is already there, but runs only if google-services.json
file is present
https://github.com/mvaljento/fcm-test/blob/main/android/app/build.gradle#L49
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out.
Bug Report
Plugin(s)
@capacitor/push-notifications: 4.1.2
Capacitor Version
Latest Dependencies:
@capacitor/cli: 4.6.3 @capacitor/core: 4.6.3 @capacitor/android: 4.6.3 @capacitor/ios: 4.6.3
Installed Dependencies:
@capacitor/cli: 4.6.3 @capacitor/core: 4.6.3 @capacitor/ios: 4.6.3 @capacitor/android: 4.6.3
Platform(s)
Android (Pixel_4_API_Tiramisu) emulator
Current Behavior
I have a new Capacitor application with Angular and Ionic. I installed Capacitor push notifications plugin as described here:
https://capacitorjs.com/docs/apis/push-notifications
PushNotifications.requestPermissions() works as expected and the app receives "request: granted", but calling PushNotifications.register() afterwards crashes the application with the following output:
VM3:246 native PushNotifications.register (#24258324)
Expected Behavior
The application should register the push notifications (or at least give an error message instead of crashing). This worked in my previous Cordova-plugin based application with the same google json.
Code Reproduction
I have a code which requests FCM permissions and then attempts to register the device like so:
I tried adding the following to capacitor.config.ts, but it made no difference:
Other Technical Details
Development platform: Macbook Pro M1 (2021), Ventura 13.1
java -version
openjdk version "19.0.2" 2023-01-17 OpenJDK Runtime Environment Homebrew (build 19.0.2) OpenJDK 64-Bit Server VM Homebrew (build 19.0.2, mixed mode, sharing)
gradle -version
Gradle 7.6
Build time: 2022-11-25 13:35:10 UTC Revision: daece9dbc5b79370cc8e4fd6fe4b2cd400e150a8
Kotlin: 1.7.10 Groovy: 3.0.13 Ant: Apache Ant(TM) version 1.10.11 compiled on July 10 2021 JVM: 19.0.2 (Homebrew 19.0.2) OS: Mac OS X 13.1 aarch64
ng version
Angular CLI: 15.1.4 Node: 16.15.0 Package Manager: npm 9.1.1 OS: darwin arm64
@angular/core: 15.1.3
ionic --version
Ionic 6.20.8
An update: I created a brand new app with no other libraries or plugins and the same thing happens.
By mistake at first I thought it worked, but I hadn't subscribed to an observable that handles the registration thus the register function never got triggered. When it triggers however, the app still crashes.
I created a repo with the test app. Please note that you might have to update the android/gradle/wrapper/gradle-wrapper.properties file with the correct gradle version if you get a "BUG" error notice when building. the correct distribution url should be:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
https://github.com/mvaljento/fcm-test
I'm running the app with:
Here's the logcat output of the crash: