Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[firebase_messaging] Setup instructions #2895

Closed
leobasilio opened this issue Jul 4, 2020 · 9 comments
Closed

[firebase_messaging] Setup instructions #2895

leobasilio opened this issue Jul 4, 2020 · 9 comments
Labels
platform: android Issues / PRs which are specifically for Android. plugin: messaging type: documentation Improvements or additions to documentation

Comments

@leobasilio
Copy link

Describe the bug
Hi. First of all, sorry I won't be able to follow the template here, but I'm really confused. Today I tried using firebase_messaging to receive push notifications on Android. After following the current README instructions, I got this error:

Type mismatch: inferred type is PluginRegistry but FlutterEngine was expected

At this line:

GeneratedPluginRegistrant.registerWith(registry);

After googling for a while, I've found some issues related to this: flutter/flutter#45231, flutter/flutter#47095, #1613, #1684

From what I could understand, the instructions on the README file are for v1 embedding. It seems to me that the package has now implemented v2 embedding, based on the this guide: Supporting the new Android plugins APIs.

All this match the guide as a package that has been migrated to v2 but still aims compatibility with v1. The same guide above has this snippet:

 public class MainActivity extends FlutterActivity {
   // You can keep this empty class or remove it. Plugins on the new embedding
   // now automatically registers plugins.
 }

So I expected that I could skip the setup instructions on README. Doing so raises the following error whenever a message is received:

PluginRegistrantCallback is not set on Android

There are also some issues on this: #248, #2017, #2077.

Long story short, the only solution that seems to work and that people keep posting over and over is this:

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

class Application : FlutterApplication(), PluginRegistrantCallback {
  override fun onCreate() {
    super.onCreate()
    FlutterFirebaseMessagingService.setPluginRegistrant(this)
  }

  override fun registerWith(registry: PluginRegistry?) {
    io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"))
  }
}

But I feel like most people including me don't understand what's going on. They just copy and paste it and it works. It's kind of a v1 registration on a v2 project.

I'm using firebase_messaging 6.0.16 and Flutter 1.17.5, and I do have the following on my manifest:

<meta-data android:name="flutterEmbedding" android:value="2" />

So here's my point:

  • The instructions on the README file don't work for the latest versions of Flutter and firebase_messaging.
  • It doesn't seem right to have that hardcoded string in my code. If that's the way to go, what's the point of the GeneratedPluginRegistrant class? The FirebaseMessagingPlugin is there, and it should work like every other plugin I'm using does.
public final class GeneratedPluginRegistrant {
  public static void registerWith(@NonNull FlutterEngine flutterEngine) {
    ShimPluginRegistry shimPluginRegistry = new ShimPluginRegistry(flutterEngine);
    flutterEngine.getPlugins().add(new io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin());
    flutterEngine.getPlugins().add(new com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin());
    flutterEngine.getPlugins().add(new ru.innim.flutter_login_facebook.FlutterLoginFacebookPlugin());
      io.flutter.plugins.flutter_plugin_android_lifecycle.FlutterAndroidLifecyclePlugin.registerWith(shimPluginRegistry.registrarFor("io.flutter.plugins.flutter_plugin_android_lifecycle.FlutterAndroidLifecyclePlugin"));
      com.aloisdeniel.geocoder.GeocoderPlugin.registerWith(shimPluginRegistry.registrarFor("com.aloisdeniel.geocoder.GeocoderPlugin"));
    flutterEngine.getPlugins().add(new io.flutter.plugins.googlemaps.GoogleMapsPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.googlesignin.GoogleSignInPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.imagepicker.ImagePickerPlugin());
    flutterEngine.getPlugins().add(new com.lyokone.location.LocationPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.packageinfo.PackageInfoPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.pathprovider.PathProviderPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin());
    flutterEngine.getPlugins().add(new io.flutter.plugins.urllauncher.UrlLauncherPlugin());
  }
}

So either we need an updated README file with proper instructions or someone with a more advanced knowledge on this plugin should try to figure out what's going on. I'm sorry, but I'm relatively new to Flutter and for the moment this is the limit of my contribution.

Flutter doctor
Run flutter doctor and paste the output below:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.17.5, on Linux, locale pt_BR.UTF-8)
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses
[!] Android Studio (version 4.0)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.46.1)
[✓] Connected device (1 available)

! Doctor found issues in 2 categories.
@shashikantx
Copy link

I have run into same issue

E/MethodChannel#plugins.flutter.io/firebase_messaging( 5925): 	at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
E/MethodChannel#plugins.flutter.io/firebase_messaging( 5925): 	at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:650)
E/MethodChannel#plugins.flutter.io/firebase_messaging( 5925): 	at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_messaging( 5925): 	at android.os.MessageQueue.next(MessageQueue.java:325)
E/MethodChannel#plugins.flutter.io/firebase_messaging( 5925): 	at android.os.Looper.loop(Looper.java:142)
E/MethodChannel#plugins.flutter.io/firebase_messaging( 5925): 	at android.app.ActivityThread.main(ActivityThread.java:6494)
E/MethodChannel#plugins.flutter.io/firebase_messaging( 5925): 	at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/firebase_messaging( 5925): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
E/MethodChannel#plugins.flutter.io/firebase_messaging( 5925): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
I/flutter ( 5925): Error caught by Crashlytics plugin <recordError>:
I/flutter ( 5925): PlatformException(error, PluginRegistrantCallback is not set., null)

According to documentations in V2 Embedding I shouldn't be registering plugins manually, but I can't get it to working that way.
Though I have flutterEngine.getPlugins().add(new io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin()); present in my GeneratedPluginRegistrant.java file.

If I register it manually, then many other plugins start failing, because I have to register all of them manually, which defeats the purpose of having v2 in first place.

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, 1.19.0-4.3.pre, on Microsoft Windows [Version 10.0.18363.900], locale en-IN)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[√] Android Studio (version 4.0)
[!] VS Code, 64-bit edition (version 1.41.1)
    X Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[√] Connected device (1 available)

! Doctor found issues in 1 category.

@TahaTesser TahaTesser added plugin: messaging type: documentation Improvements or additions to documentation platform: android Issues / PRs which are specifically for Android. labels Jul 6, 2020
@TahaTesser
Copy link

I agree readme and example needs update

@cannibal-kush
Copy link

To add to this, this page: https://firebase.flutter.dev/docs/overview/

Still uses the method firebase.initializeApp() which is very confusing as it seems not to exist.

@inpendio
Copy link

I agree readme and example needs update

Could you just explain what docs should I use?
I have installed firebase_core 0.4.5., but on master branch the docs and examples seems to follow 1.0.0 release ( which is not yet available)...

@TahaTesser
Copy link

@inpendio
I suggest you use doc from pub page for now with 0.4.5

@dmiedev
Copy link

dmiedev commented Jul 23, 2020

Very frustrating... :/

@mcavazotti
Copy link

I am having the same issue

@ir4ever
Copy link

ir4ever commented Oct 26, 2020

Tem o codigo para .java?

@Salakar
Copy link
Member

Salakar commented Nov 5, 2020

Hey all 👋

As part of our roadmap (#2582) we've just shipped a complete rework of the firebase_messaging plugin that aims to solve this and many other issues. We now have in-depth and up to date documentation for integrating with FlutterFire messaging.

If you can, please try out the dev release (see the migration guide for upgrading and for changes) and if you have any feedback then join in the discussion here.

Given the scope of the rework I'm going to go ahead and close this issue in favor of trying out the latest plugin.

Thanks everyone.

@Salakar Salakar closed this as completed Nov 5, 2020
@firebase firebase locked and limited conversation to collaborators Dec 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform: android Issues / PRs which are specifically for Android. plugin: messaging type: documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

9 participants