Flutter Community

Flutter - Migrating to V2 Embedding

thumbnail
  • You may receive a warning message about using a deprecated version of the Android embedding when running "pub get" in a Flutter project created prior to version 1.12 of Flutter.
  • There are two methods for migrating the project to V2 Embedding: manually or by creating a new project and copying the code.
  • If manually migrating, open the MainActivity.kt (or .java) file and remove any content, leaving only the class declaration. Add the necessary metadata inside the application tags in the file.
  • Adjust the styles.xml file to configure the LaunchTheme with the desired splash screen behavior.
  • The AndroidManifest.xml file will need to be modified to reflect the changes made.
  • It may be necessary to migrate the project to use AndroidX libraries instead of the older support libraries. This can be done by opening the android folder as a standalone project, clicking on Refactor, and selecting Migrate to AndroidX.
  • Errors that may occur during the migration process include issues with mutable Windows environment variable map, invalid content found in the base-extension element, and warnings about the SDK XML version.
  • To resolve these issues, update the gradle version in the Project Structure settings and ensure that the Android SDK Tools are up to date.
  • Once the migration is complete and any errors have been resolved, the project should compile and run smoothly.