How to migrate Older Version of Flutter to Flutter Android Embedding 2

In order to better support the execution environments of adding Flutter to an existing project, the old Android platform-side wrappers hosting the Flutter runtime at io.flutter.app.FlutterActivity and their associated classes are now deprecated. New wrappers at io.flutter.embedding.android.FlutterActivity and associated classes now replace them.

Your existing full-Flutter projects aren’t immediately affected and will continue to work as before for the foreseeable future.

To migrate your project, follow the following steps:

  • Remove the body of your MainActivity.java or MainActivity.kt and change the FlutterActivity import. The new FlutterActivity no longer requires manually registering your plugins. It will now perform the registration automatically when the underlaying FlutterEngine is created. your file should be like this
package com.appname.app
import io.flutter.embedding.android.FlutterActivity 

class MainActivity: FlutterActivity() { 

}

If you had existing custom platform channel handling code in your MainActivity.java or MainActivity.kt then move the channel registration part of the code in your onCreate into the configureFlutterEngine override of the FlutterActivity subclass and use flutterEngine.getDartExecutor().getBinaryMessenger() as the binary messenger rather than getFlutterView().

  • Open android/app/src/main/AndroidManifest.xml.
  • Remove the reference to FlutterApplication from the application tag. and your file should be like this

Previous configuration:

<application    
android:name="io.flutter.app.FlutterApplication"    >    
<!-- code omitted --> 
</application> 

New configuration:

<application   >   
<!-- code omitted --> 
</application> 
  • Update splash screen behavior (if splash behavior is desired).In AndroidManifest.xml remove all <meta-data> tags with key android:name="io.flutter.app.android.SplashScreenUntilFirstFrame".
  • Add a new <meta-data> tag under <application>.
<meta-data   
android:name="flutterEmbedding"  
android:value="2" /> 
enter image description here

Reference:
https://stackoverflow.com/questions/65018588/your-flutter-application-is-created-using-an-older-version-of-the-android-embedd

Leave a Comment

Your email address will not be published. Required fields are marked *