-
Notifications
You must be signed in to change notification settings - Fork 6k
Register plugins at the right time, once #15979
Conversation
There was a problem hiding this 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.
shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java
Outdated
Show resolved
Hide resolved
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. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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}. |
There was a problem hiding this comment.
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); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor nit: extra line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM + nits
Is there a workaround to fix this issue on stable channel? I'm using Google maps and Firebase and getting notifications twice |
… (#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
@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. |
Switching to master could be a good temporary solution for me. |
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.
This reverts commit 21ea450.
Description
Currently we're automatically registering plugins both when the
FlutterEngine is constructed and in the
flutter create
template, whenFlutterActivity#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 mostapps.
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.
FlutterActivity
'sconfigureFlutterEngine
hook. Anyone usingFlutterActivity
(orFlutterFragment
) should be automatically registered once that hook iscalled. Right now the
flutter create
template overrides the base classmethod 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