Flutter build failed due to use of deprecated Android v1 embedding

Viewed 8108

I have an error in the flutter project that I cloned from GitHub. I tried this method but it didn't work

<application
    android:name="io.flutter.app.FlutterApplication"

To:

<application
        android:name="${applicationName}"

error:

enter image description here

AndroidManifest.xml:

enter image description here

4 Answers

It may sound like a fake solution, but indeed, the easiest way to resolve this is:

  1. Delete the android folder.
  2. Run flutter create .

The command will recreate the android folder with the already migrated code. Also, the command will create folders for the other stable platforms (e.g. web, windows), so you could ignore those and just delete them or trigger the flutter create command by defining android platform - flutter create --platforms=android ..

Add the following code in android manifest after activity

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

enter image description here

In project build.gradle add the following code in buildscript

ext.kotlin_version = '1.6.10'

enter image description here

And change gradle version in gradle-wrapper.properties

enter image description here

My manifest file

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.stackoverflowexample">
   <application
        android:label="stackoverflowexample"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

The best solution I found when I got this problem with my older Flutter projects is to start fresh.

  1. Rename the old project folder.
  2. Create a new Flutter project using the latest Android Studio or command line.
  3. Copy/paste the old code from your backup folder.
  4. Be careful not to replace any of the control files: pubspec.yaml, Android folder, iOS folder, Gradle, etc.
  5. You will find the problem solved.
Related