kunaljosh369
kunaljosh369

Reputation: 305

Package not found in Application.java in flutter FlutterFirebaseMessaging plugin

I am working with firebase messaging. I followed the steps as given in readme of the plugin. But my application .java is giving an error.

Application.java

package com.app.demoapp;
import com.transistorsoft.flutter.backgroundfetch.BackgroundFetchPlugin;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;

public class Application extends FlutterApplication implements PluginRegistry.PluginRegistrantCallback {
  public void onCreate() {
    super.onCreate();
    FlutterFirebaseMessagingService.setPluginRegistrant(this);
    BackgroundFetchPlugin.setPluginRegistrant(this);
  }

  @Override
  public void registerWith(PluginRegistry registry) {
    GeneratedPluginRegistrant.registerWith(registry);
  }
}

Error:

error: cannot find symbol
    FlutterFirebaseMessagingService.setPluginRegistrant(this);                                                     
                                   ^                                                                               
  symbol:   method setPluginRegistrant(Application)                                                                
  location: class FlutterFirebaseMessagingService                                                                  
1 error                                                                                                            

Upvotes: 5

Views: 3464

Answers (3)

bachtiyar93
bachtiyar93

Reputation: 13

just set with

import io.flutter.app.FlutterApplication;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback;
import io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService;


public class Application extends FlutterApplication implements 
PluginRegistrantCallback {
@Override
public void onCreate() {
    super.onCreate();
    FlutterFirebaseMessagingService.setPluginRegistrant(this);
}

@Override
public void registerWith(PluginRegistry registry) {
    FirebaseCloudMessagingPluginRegistrant.registerWith(registry);
}
}

And make FirebaseCloudMessagingPluginRegisttrant java

Upvotes: 0

haroldolivieri
haroldolivieri

Reputation: 2283

Looks like the instructions file is outdated, it was missing a very important step that you can check at the github repository README

Add the com.google.firebase:firebase-messaging dependency in your app-level build.gradle file that is typically located at /android/app/build.gradle.

dependencies {
  // ...

  implementation 'com.google.firebase:firebase-messaging:20.1.0'
}

Upvotes: 0

Mahmoud Abu Alheja
Mahmoud Abu Alheja

Reputation: 3668

I have faced the same problem and so far I have not found any solution

but If you want just show notification with out handle it in background and just lunch app when click on it

remove FlutterFirebaseMessagingService.setPluginRegistrant(this);and the notification will work fine as Notification messages type

if you don't know about Notification type in fcm

refer to Message types

With FCM, you can send two types of messages to clients:

1- Notification messages, sometimes thought of as "display messages." These are handled by the FCM SDK automatically.

2- Data messages, which are handled by the client app.

so we use Notification messages here until find solution for handle Data messages

Upvotes: 2

Related Questions