Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Register plugins at the right time, once #15979

Merged
merged 3 commits into from
Jan 25, 2020
Merged

Register plugins at the right time, once #15979

merged 3 commits into from
Jan 25, 2020

Conversation

mklim
Copy link
Contributor

@mklim mklim commented Jan 24, 2020

Description

Currently we're automatically registering plugins both when the
FlutterEngine is constructed and in the flutter create template, when
FlutterActivity#configureFlutterEngine is called. The initial
registration is too early to contain a reference to the activity and the
second registration can cause problems in some plugins.

This alters the flow so automatic registration happens in two discrete
places, and contains the activity in its first and only call for most
apps.

  1. We're no longer automatically registering plugins on FlutterEngine
    in any of our activities/fragments at construction time. But since the
    FlutterEngine default constructor still automatically registers plugins,
    anyone constructing the engine themselves (for example, in a service) is
    still going to get automatic registration at FlutterEngine
    instantiation time.
  2. We now automatically register plugins in the base FlutterActivity's
    configureFlutterEngine hook. Anyone using FlutterActivity (or
    FlutterFragment) should be automatically registered once that hook is
    called. Right now the flutter create template overrides the base class
    method with a subclass that registers everything manually in the same
    spot. But with this in place we can safely recommend to remove the
    subclass and rely on this hook to automatically register going forward.
    Registering at this time means activity is set correctly.

Related Issues

@mklim mklim requested a review from matthew-carroll January 24, 2020 23:40
@auto-assign auto-assign bot requested a review from gaaclarke January 24, 2020 23:40
@mklim mklim requested a review from blasten January 24, 2020 23:41
Copy link
Contributor

@matthew-carroll matthew-carroll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks.

FYI, I'm still waiting on LUCI to merge in my related PR.

Michael Klimushyn added 2 commits January 24, 2020 16:18
Currently we're automatically registering plugins both when the
FlutterEngine is constructed and in the `flutter create` template, when
FlutterActivity#configureFlutterEngine is called. The initial
registration is too early to contain a reference to the activity and the
second registration can cause problems in some plugins.

This alters the flow so automatic registration happens in two discrete
places, and contains the `activity` in its first and only call for most
apps.

1. We're no longer automatically registering plugins on `FlutterEngine`
in any of our activities/fragments at construction time. But since the
FlutterEngine default constructor still automatically registers plugins,
anyone constructing the engine themselves (for example, in a service) is
still going to get automatic registration at `FlutterEngine`
instantiation time.
2. We now automatically register plugins in the base `FlutterActivity`'s
`configureFlutterEngine` hook. Anyone using `FlutterActivity` (or
`FlutterFragment`) should be automatically registered once that hook is
called. Right now the `flutter create` template overrides the base class
method with a subclass that registers everything manually in the same
spot. But with this in place we can safely recommend to remove the
subclass and rely on this hook to automatically register going forward.
Registering at this time means `activity` is set correctly.
1. Previous commit accidentally ate `dartVmArgs`, change the new
`FlutterEngine` constructor so that it still is passed through.
2. `GeneratedPluginRegistrant` is in `.gitignore` so the last commit
didn't have the fake, force the test fake to be added into version
control and commit it.
@@ -950,4 +957,28 @@ public void onFlutterUiNoLongerDisplayed() {
// no-op
}

/**
* Registers all plugins that an app lists in its pubspec.yaml.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit: plugins that support the android platform

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would be redundant to point out here. This is already a Javadoc comment in the Android embedding specifically and not a generic part of the engine's C++ source code, so I don't think it's worth pointing out that this logic is Android-only. If you feel strongly about it I can update it though.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at all. 🙂Although, if someone wants to understand why a plugin isn't added to the GeneratedPluginRegistrant, the comment might be useful.

The current definition of supporting the Android platform is a plugin that contains android/build.gradle.

https://api.flutter.dev/javadoc/io/flutter/app/FlutterActivity.html.

* Registers all plugins that an app lists in its pubspec.yaml.
* <p>
* The Flutter tool generates a class called GeneratedPluginRegistrant, which includes the code
* necessary to register every plugin in the pubspec.yaml with a given {@code FlutterEngine}.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

this(context, FlutterLoader.getInstance(), new FlutterJNI(), dartVmArgs, automaticallyRegisterPlugins);
}


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit: extra line

Copy link

@blasten blasten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM + nits

@mklim mklim merged commit 6fa1fcd into flutter:master Jan 25, 2020
@mklim mklim deleted the fix_registration branch January 25, 2020 08:35
@scognito
Copy link

Is there a workaround to fix this issue on stable channel? I'm using Google maps and Firebase and getting notifications twice

engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 25, 2020
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Jan 25, 2020
… (#49485)

flutter/engine@f30ff4f...6fa1fcd

git log f30ff4f..6fa1fcd --first-parent --oneline
2020-01-25 [email protected] Register plugins at the right time, once (flutter/engine#15979)


If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected] on the revert to ensure that a human
is aware of the problem.

To report a problem with the AutoRoller itself, please file a bug:
https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md
@mklim
Copy link
Contributor Author

mklim commented Jan 27, 2020

@scognito there isn't a good workaround on stable yet, sorry. Because of how this is broken there isn't an obvious workaround that doesn't cause a secondary issue. I'm going to see if this can be hotfixed, but for now it's only rolled into the master channel.

@scognito
Copy link

Switching to master could be a good temporary solution for me.
Once switched to master, and after a flutter clean and build, do I need to change something else?
Thanks for your efforts.

NoamDev pushed a commit to NoamDev/engine that referenced this pull request Feb 27, 2020
Currently we're automatically registering plugins both when the
FlutterEngine is constructed and in the `flutter create` template, when
FlutterActivity#configureFlutterEngine is called. The initial
registration is too early to contain a reference to the activity and the
second registration can cause problems in some plugins.

This alters the flow so automatic registration happens in two discrete
places, and contains the `activity` in its first and only call for most
apps.

1. We're no longer automatically registering plugins on `FlutterEngine`
in any of our activities/fragments at construction time. But since the
FlutterEngine default constructor still automatically registers plugins,
anyone constructing the engine themselves (for example, in a service) is
still going to get automatic registration at `FlutterEngine`
instantiation time.
2. We now automatically register plugins in the base `FlutterActivity`'s
`configureFlutterEngine` hook. Anyone using `FlutterActivity` (or
`FlutterFragment`) should be automatically registered once that hook is
called. Right now the `flutter create` template overrides the base class
method with a subclass that registers everything manually in the same
spot. But with this in place we can safely recommend to remove the
subclass and rely on this hook to automatically register going forward.
Registering at this time means `activity` is set correctly.
NoamDev added a commit to NoamDev/engine that referenced this pull request Feb 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
5 participants