Is there a way to use a package plugin for only 1 (or specific) platform, e.g. "iOS, but not Android or Web"? For example, firebase_messaging supports Android, iOS, macOS and Web, but I only want it to be installed on Android where FCM is required. I will support other platforms with my own code/ other libraries.
I do not want the plugin to be registered on iOS because it may be causing a crash/ interfering with my application because it does Objective-C method swizzling. I guess I don't want it's registerWithRegistrar method called.
Note: this is different to supporting specific platforms. i.e. I still support Android and iOS, I just don't want one plugin to register on iOS. Having thought about this more, I don't just want to prevent plugin registration, but also compilation. This is because the compilation step can affect the build/ other plugins.
GeneratedPluginRegistrantA class is autogenerated to register all plugins:
GeneratedPluginRegistrant.java@Keep
public final class GeneratedPluginRegistrant {
public static void registerWith(@NonNull FlutterEngine flutterEngine) {
flutterEngine.getPlugins().add(new io.ably.flutter.plugin.AblyFlutterPlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.firebase.core.FlutterFirebaseCorePlugin());
flutterEngine.getPlugins().add(new io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin());
flutterEngine.getPlugins().add(new com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin());
}
}
GeneratedPluginRegistrant.m@implementation GeneratedPluginRegistrant
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry {
[AblyFlutterPlugin registerWithRegistrar:[registry registrarForPlugin:@"AblyFlutterPlugin"]];
[FLTFirebaseCorePlugin registerWithRegistrar:[registry registrarForPlugin:@"FLTFirebaseCorePlugin"]];
[FLTFirebaseMessagingPlugin registerWithRegistrar:[registry registrarForPlugin:@"FLTFirebaseMessagingPlugin"]];
[FlutterApnsPlugin registerWithRegistrar:[registry registrarForPlugin:@"FlutterApnsPlugin"]];
[FlutterLocalNotificationsPlugin registerWithRegistrar:[registry registrarForPlugin:@"FlutterLocalNotificationsPlugin"]];
}
@end
You actually call that method, registerWithRegistry: in your AppDelegate, e.g.
In your Android app's MainActivity:
public class MainActivity extends FlutterActivity {
@Override
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
In your iOS app's application:didFinishLaunchingWithOptions::
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
// Override point for customization after application launch.
if (@available(iOS 10.0, *)) {
[UNUserNotificationCenter currentNotificationCenter].delegate = (id<UNUserNotificationCenterDelegate>) self;
}
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
@end
GeneratedPluginRegistrant.AndroidManifest.xml will still be merged into your applications Manifest.Implement PluginRegistrant.java by copying the contents from GeneratedPluginRegistrant.java. Call PluginRegistrant.registerWith(flutterEngine); instead.
Implement PluginRegistrant.m by copying the contents from GeneratedPluginRegistrant.m. Call [PluginRegistrant registerWithRegistry:self]; instead.
Not necessarily hard questions, but I'm leaving this for later. :)
GeneratedPluginRegistrant know which plugins to register? (read the code generator)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With