When an application declares V2 embedding then plugin is added in backward compatibility mode and actually works in UI mode when Activity instance exists. But plugin causes a crash when app runs in background and performs regular plugins registration via calling:
io.flutter.plugins.GeneratedPluginRegistrant.registerWith
Then flutter_email_sender crashes:
E/AndroidRuntime( 2027): Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void io.flutter.plugin.common.BinaryMessenger.setMessageHandler(java.lang.String, io.flutter.plugin.common.BinaryMessenger$BinaryMessageHandler)' on a null object reference
E/AndroidRuntime( 2027): at io.flutter.plugin.common.MethodChannel.setMethodCallHandler(MethodChannel.java:119)
E/AndroidRuntime( 2027): at com.sidlatau.flutteremailsender.FlutterEmailSenderPlugin$Companion.registerWith(FlutterEmailSenderPlugin.kt:35)
E/AndroidRuntime( 2027): at com.sidlatau.flutteremailsender.FlutterEmailSenderPlugin.registerWith(Unknown Source:2)
E/AndroidRuntime( 2027): at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:31)
Proper implementation of Android V2 embedding solves the issue
Latest flutter plugin guidelines suggest to switch Android V2 embedding API. For migration steps see https://flutter.dev/docs/development/packages-and-plugins/plugin-api-migration
When an application declares V2 embedding then plugin is added in backward compatibility mode and actually works in UI mode when Activity instance exists. But plugin causes a crash when app runs in background and performs regular plugins registration via calling:
io.flutter.plugins.GeneratedPluginRegistrant.registerWith
Then flutter_email_sender crashes:
Proper implementation of Android V2 embedding solves the issue