Opening an old Flutter project says: Your Flutter application is created using an older version of the Android embedding

My flutter SDK version : 1.22.4

 

When opening an old flutter project, you may encounter the following two warnings ( the new project created by FlutterSDK1.22.4 will not have these two problems, so it is easy to find a way to fix the problem by comparing the new project with the old project ):

Warning 1.

  1. Your Flutter application is created using an older version of the Android
  2. embedding. It's being deprecated in favor of Android embedding v2.

Solution : Open the AndroidManifest.xml file in the app folder in the android directory, and add the following code below the activity tag:

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

Then when I run the project, I get the following error:

  1. error: incompatible types: MainActivity cannot be converted to FlutterEngine
  2. GeneratedPluginRegistrant.registerWith(this)

Solution: Comment out this line of code and it's ok

 

Warning 2,

  1. [!] Your app isn't using AndroidX.
  2.     To avoid potential build failures, you can quickly migrate your app by following the steps on https://goo.gl/CP92wY.

Solution : Add the following code to gradle.properties in the android folder:

  1. android.enableJetifier=true
  2. android.useAndroidX=true

Related: Opening an old Flutter project says: Your Flutter application is created using an older version of the Android embedding