-
Notifications
You must be signed in to change notification settings - Fork 30k
Description
As a plugin developer, I get numerous issues regarding this error on a regular basis. There are many unrelated causes for this error, and to make matters worse, the error message identifies the plugin that was attempting to use platform channels although that is not necessarily the plugin that is responsible for the error, and so you get issues posted by app developers on the wrong projects asking for the bug to be fixed. Furthermore, sometimes the error is caused by an incorrectly written plugin and other times it is caused by something the app developer did or didn't do. In both cases, there is a lack of documentation to help both the plugin developer and the app developer to navigate this issue and track down the root of what's causing it.
What I think is sorely needed is an official MissingPluginException FAQ listing all of the causes for this error and how to address them.
Additionally, since a lot of these errors can be caused whenever an app is creating a background FlutterEngine and it fails to register plugins for some reason, the documentation for Flutter background execution needs to be improved. The following page, for example, still refers to an old Medium article written by Ben Konyi that desperately needs an update:
https://flutter.dev/docs/development/packages-and-plugins/background-processes
On the Android side, the linked article has still not been updated to explain the v2 architecture and plugins that don't do this correctly may fail to do plugin registration correctly in certain circumstances. Yet, this is what the official Flutter documentation refers to.
Here is something that I (as a plugin developer) cannot figure out from the documentation: In that medium article, Ben uses this callback trick on Android to allow plugins to be registered in the background, but it is not needed anymore under v2:
// In a custom Application subclass
public void onCreate() {
super.onCreate();
GeofencingService.setPluginRegistrant(this);
}But the same article uses this trick in the iOS implementation:
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Register the plugins with the AppDelegate
registerPlugins(self);
// Set registerPlugins as a callback within GeofencingPlugin. This allows
// for the Geofencing plugin to register the plugins with the background
// FlutterEngine instance created to handle events. If this step is skipped,
// other plugins will not work in the geofencing callbacks!
[GeofencingPlugin setPluginRegistrantCallback:registerPlugins];
// Override point for customization after application launch.
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}Is this trick still required in iOS but not required in Android? If I view the latest version of the geofencing plugin on GitHub, it still has this trick in it. However, the flutter_isolate plugin doesn't do this trick and STILL seems to work in almost most cases, although still people sometimes report that plugins do not get registered in some cases, and it is never obvious what causes it to work with some combination of plugin dependencies and not others. It is typically the presence of one culprit plugin that if removed from the project, allows everything to work again.
In almost every case, it is extremely difficult to track down which plugin is causing plugin registration to fail except by removing plugins one by one until things work again. Perhaps this is also cause to try to improve the error messages so that the real source of the problem can be more easily pinpointed.