-
Notifications
You must be signed in to change notification settings - Fork 6k
Deduplicate plugin registration logic and make error logs visible - take 2 #25395
Changes from 2 commits
4859b9f
a52d4d3
2e6d28b
a709c21
e4490ca
30f8332
1db4752
2b4227d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -919,12 +919,21 @@ public PlatformPlugin providePlatformPlugin( | |
| * <p>This method is called after {@link #provideFlutterEngine(Context)}. | ||
| * | ||
| * <p>All plugins listed in the app's pubspec are registered in the base implementation of this | ||
| * method. To avoid automatic plugin registration, override this method without invoking super(). | ||
| * To keep automatic plugin registration and further configure the flutterEngine, override this | ||
| * method, invoke super(), and then configure the flutterEngine as desired. | ||
| * method unless the FlutterEngine for this activity was externally created. To avoid the | ||
| * automatic plugin registration for implicitly created FlutterEngines, override this method | ||
| * without invoking super(). To keep automatic plugin registration and further configure the | ||
| * FlutterEngine, override this method, invoke super(), and then configure the FlutterEngine as | ||
| * desired. | ||
| */ | ||
| @Override | ||
| public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { | ||
| if (delegate.isFlutterEngineFromHost()) { | ||
| // If the FlutterEngine was explicitly built and injected into thi FlutterActivity, the | ||
| // builder should explicitly decide whether to automatically register plugins via the | ||
| // FlutterEngine's construction parameter or via the AndroidManifest metadata. | ||
| return; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, should we report this? Potentially with an exception or a return value?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. both the engine registration and the activity registration paths are called 99% of the time. We should just ignore the second call. |
||
| } | ||
|
|
||
| GeneratedPluginRegister.registerGeneratedPlugins(flutterEngine); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -580,12 +580,21 @@ public FlutterEngine provideFlutterEngine(@NonNull Context context) { | |
| * <p>This method is called after {@link #provideFlutterEngine(Context)}. | ||
| * | ||
| * <p>All plugins listed in the app's pubspec are registered in the base implementation of this | ||
| * method. To avoid automatic plugin registration, override this method without invoking super(). | ||
| * To keep automatic plugin registration and further configure the flutterEngine, override this | ||
| * method, invoke super(), and then configure the flutterEngine as desired. | ||
| * method unless the FlutterEngine for this activity was externally created. To avoid the | ||
| * automatic plugin registration for implicitly created FlutterEngines, override this method | ||
| * without invoking super(). To keep automatic plugin registration and further configure the | ||
| * FlutterEngine, override this method, invoke super(), and then configure the FlutterEngine as | ||
| * desired. | ||
| */ | ||
| @Override | ||
| public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { | ||
| if (flutterFragment.isFlutterEngineInjected()) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the key bit that is different from the previous PR. It seems like there was a long-standing bug where even if the engine says don't auto-register, the activity registers it anyway, which makes it hard to test in while avoiding annoying registration errors. Comically, this change makes everything harder to test since only a non-injected engine has the auto-registering behavior but a non-injected engine is harder to prevent real JNI calls on. Add more plumbing to make a default constructed engine testable. |
||
| // If the FlutterEngine was explicitly built and injected into thi FlutterActivity, the | ||
|
xster marked this conversation as resolved.
Outdated
|
||
| // builder should explicitly decide whether to automatically register plugins via the | ||
| // FlutterEngine's construction parameter or via the AndroidManifest metadata. | ||
| return; | ||
| } | ||
|
|
||
| GeneratedPluginRegister.registerGeneratedPlugins(flutterEngine); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.