Your Flutter application is created using an older version of the Android embedding

Recently I opened my old project and there is a warning right now that nothing like this was happening before

Warning looks like

Warning
──────────────────────────────────────────────────────────────────────────────
Your Flutter application is created using an older version of the Android
embedding. It's being deprecated in favor of Android embedding v2. Follow the
steps at

https://flutter.dev/go/android-project-migration

to migrate your project.

flutter doctor -v summary

[✓] Flutter (Channel stable, 1.22.2, on Mac OS X 10.15.3 19D76, locale en-GB)
    • Flutter version 1.22.2 at /Users/pkimac/Development/flutter
    • Framework revision 84f3d28555 (6 weeks ago), 2020-10-15 16:26:19 -0700
    • Engine revision b8752bbfff
    • Dart version 2.10.2

 
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    • Android SDK at /Users/pkimac/Library/Android/sdk
    • Platform android-30, build-tools 29.0.3
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 11.3.1, Build version 11C504
    • CocoaPods version 1.10.0.rc.1

[!] Android Studio (version 4.1)
    • Android Studio at /Applications/Android Studio.app/Contents
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)

[✓] Connected device (1 available)
    • iPhone 11 Pro (mobile) • 7A52F1D0-79F7-471C-AA62-3C106114A1A9 • ios • com.apple.CoreSimulator.SimRuntime.iOS-13-3 (simulator)
    ! Error: Paresh’s iPhone has recently restarted. Xcode will continue when Paresh’s iPhone is unlocked. (code -14)

! Doctor found issues in 1 category.

What does this mean and how can I solve this warning?

Answer

This warning occurs if you have created your project before version 1.12

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:

  1. 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().

  2. Open android/app/src/main/AndroidManifest.xml.

  3. 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>
    
  4. 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".

  5. Add a new <meta-data> tag under <application>.

    <meta-data
      android:name="flutterEmbedding"
      android:value="2" />
    

    enter image description here

For more info see: https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects#full-flutter-app-migration

Leave a Reply

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