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
orMainActivity.kt
and change theFlutterActivity
import. The newFlutterActivity
no longer requires manually registering your plugins. It will now perform the registration automatically when the underlayingFlutterEngine
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 keyandroid:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
. - Add a new
<meta-data>
tag under<application>
.
<meta-data
android:name="flutterEmbedding"
android:value="2" />