ionic-team / capacitor-plugins

Official plugins for Capacitor ⚡️
485 stars 563 forks source link

Push-notification v4 throws Cannot resolve method 'getToken' in 'FirebaseMessaging' #1219

Closed kendyl93 closed 1 year ago

kendyl93 commented 1 year ago

Bug Report

Plugin(s)

"@capacitor/push-notifications": "4.0.0",

Capacitor Version

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 4.3.0
  @capacitor/core: 4.3.0
  @capacitor/android: 4.3.0
  @capacitor/ios: 4.3.0

Installed Dependencies:

  @capacitor/cli: 4.3.0
  @capacitor/android: 4.3.0
  @capacitor/core: 4.3.0
  @capacitor/ios: 4.3.0

[success] iOS looking great! 👌
[success] Android looking great! 👌

Platform(s)

Current Behavior

When I upgraded capacitor with plugins from version 3 to 4 I cannot run android build. PushNotificationsPlugin throws me an error.

Build output:

/Users/myapp/Desktop/myapp_app_ionic/node_modules/@capacitor/push-notifications/android/src/main/java/com/capacitorjs/plugins/pushnotifications/PushNotificationsPlugin.java:79: error: cannot find symbol
            .getToken()
            ^
  symbol:   method getToken()
  location: class FirebaseMessaging
    @PluginMethod
    public void register(PluginCall call) {
        FirebaseMessaging.getInstance().setAutoInitEnabled(true);
        FirebaseMessaging
            .getInstance()
            .getToken()  // <- Cannot resolve method 'getToken' in 'FirebaseMessaging'
            .addOnCompleteListener(
                task -> {
                    if (!task.isSuccessful()) {
                        sendError(task.getException().getLocalizedMessage());
                        return;
                    }
                    sendToken(task.getResult());
                }
            );
        call.resolve();
    }

When I downgraded plugin to previous version ("@capacitor/push-notifications": "^1.0.7") it is working fine.

Expected Behavior

App should run without any issues

Code Reproduction

  1. Update capacitor with plugins from v3 to v4 using migrator

Other Technical Details

Android Studio Dolphin | 2021.3.1 Build #AI-213.7172.25.2113.9014738, built on August 31, 2022 Runtime version: 11.0.13+0-b1751.21-8125866 x86_64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 12.6 GC: G1 Young Generation, G1 Old Generation Memory: 1280M Cores: 8 Registry: external.system.auto.import.disabled=true ide.text.editor.with.preview.show.floating.toolbar=false

Ionitron commented 1 year ago

This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue.

Please see the Contributing Guide for how to create a Code Reproduction.

Thanks! Ionitron 💙

Ionitron commented 1 year ago

It looks like this issue didn't get the information it needed, so I'll close it for now. If I made a mistake, sorry! I am just a bot.

Have a great day! Ionitron 💙

jcesarmobile commented 1 year ago

Since there was no response is hard to tell, but this is most likely caused by using an old firebaseMessagingVersion variable version in variables.gradle file. The capacitor 4 upgrade guide recommends to update it to 23.0.5. Or delete the firebaseMessagingVersion variable so the plugin always use the default one.

ionitron-bot[bot] commented 1 year ago

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.