Skip to content

This script helps to sort and specify the order of Flutter plugin registration.

License

Notifications You must be signed in to change notification settings

eJamesLin/FlutterPluginSort

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

FlutterPluginSort

About

  • This is the script help to sort the GeneratedPluginRegistrant.m generated by Flutter.
  • This script also provide a function to automatically move specified plugin to the last, if the plugin should be run as the last one.
// Flutter initially generated `GeneratedPluginRegistrant.m`, plugins register order is random
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry {
  [SomeDeeplinkPlugin registerWithRegistrar:[registry registrarForPlugin:@"SomeDeeplinkPlugin"]];
  [BPlugin registerWithRegistrar:[registry registrarForPlugin:@"BPlugin"]];
  [CPlugin registerWithRegistrar:[registry registrarForPlugin:@"CPlugin"]];
  [APlugin registerWithRegistrar:[registry registrarForPlugin:@"APlugin"]];  
}

// Sorted result, and the deeplink plugin should be loaded as the last one
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry {
  [APlugin registerWithRegistrar:[registry registrarForPlugin:@"APlugin"]];
  [BPlugin registerWithRegistrar:[registry registrarForPlugin:@"BPlugin"]];
  [CPlugin registerWithRegistrar:[registry registrarForPlugin:@"CPlugin"]];
  [SomeDeeplinkPlugin registerWithRegistrar:[registry registrarForPlugin:@"SomeDeeplinkPlugin"]];
}

The reason why to use this script

  • The plugin register order in GeneratedPluginRegistrant.m's registerWithRegistry: is randomly generated by Flutter, which in some cases will cause some issues.
  • Due to this uncertainty, the 3rd-party login deeplink back to App might sometimes be failed. The reason is that, for example, after allow login at Facebook App, Facebook App will try to launch the original App by deeplink, and bring back auth token along with it. But this deeplink, might be intercept by other flutter plugins, so Facebook SDK will never receive that deeplink, and the login action will be failed.
  • Also the FirebaseDynamicLinks deeplink/universal link might also be incercepted by other plugin, and the deferred deep link will therefore be failed.
  • More detail information is written at this article

Usage

  • Sort the plugins:
perl FlutterPluginSortObjC.pl
  • Move plugin to the last:
perl FlutterPluginSortObjC.pl -last [plugin_name]
  • Add the sorted GeneratedPluginRegistrant.m into version-control system.

XCode Integration

  • At Xcode Build Phases, click the Add New Run Script Phase
  • Drag the run script before Compile Sources
  • Type the command perl FlutterPluginSortObjC.pl
  • Ready to build some code!

About

This script helps to sort and specify the order of Flutter plugin registration.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages