[Fixed] "Build failed due to use of deprecated Android v1 embedding" when building Flutter app – Android

Photo of author
Written By M Ibrahim
android flutter

Quick Fix: In android\app\src\main\AndroidManifest.xml, change application android:name from io.flutter.app.FlutterApplication to application name. Add android:name="flutterEmbedding" and android:value="2" to meta-data in application tag if not present.

The Problem:

Error message "Build failed due to use of deprecated Android v1 embedding" is encountered while building a Flutter app, indicating that the app is still using the outdated Android v1 embedding. The message suggests migrating to the newer Android v2 embedding or temporarily ignoring the deprecation warning using the "–ignore-deprecation" flag, but emphasizes that v1 embedding will be removed in future Flutter versions.

The Solutions:

Solution 1: Change the Android Manifest file

To fix the error, you need to change the android/app/src/main/AndroidManifest.xml file. Here’s what you need to do:

Step 1: Find the following line in the AndroidManifest.xml file:

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

Step 2: Replace it with the following:

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

Step 3: Add the following three lines if they do not already exist:

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

The flutterEmbedding meta-data tag is used by the Flutter tool to generate GeneratedPluginRegistrant.java. Save the changes to the AndroidManifest.xml file and rebuild your project. The error should be resolved.

Solution 2: Change AndroidManifest.xml file with FlutterApplication and Add Meta-data Tag

To fix the error “Build failed due to use of deprecated Android v1 embedding,” you need to modify your project’s AndroidManifest.xml file. Here’s a step-by-step solution:

1. Open the AndroidManifest.xml file located at [project_root]/android/app/src/main/AndroidManifest.xml.

2. Locate the <application> element.

3. Find the line that sets the android:name attribute to “io.flutter.app.FlutterApplication”. This line typically looks like:

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

</application>

  1. Change the android:name attribute to your application’s name. For example:

<application
android:name="com.yourcompany.myapp"

</application>

  1. After the <application> tag, add the following two lines:

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

These lines specify that you want to use the Android v2 embedding for Flutter.

  1. Save the AndroidManifest.xml file.

  2. Run the build command again.

This should resolve the error and allow you to build your Flutter app successfully.

Solution 4: Update project according to new changes

Upgrading your project according to version updates is important. Here’s how to do it:

Manifest:

  • Replace the line starting with &lt;application android:name=&quot;io.flutter.app.FlutterApplication&quot; with &lt;application android:name=&quot;${applicationName}&quot;.

  • Within the <application..> tags, add the following lines:

    • &lt;application android:exported=&quot;true&quot;...&gt;
    • &lt;meta-data android:name=&quot;flutterEmbedding&quot; android:value=&quot;2&quot; /&gt;

MainActivity.kt:

  • If you’re using Kotlin, ensure that your MainActivity.kt file is structured as follows:
    • package com.yourpackage.....
    • import io.flutter.embedding.android.FlutterActivity
    • class MainActivity: FlutterActivity() { //If you have some native code put it back }

MainActivity.java:

  • If you’re using Java, make sure your MainActivity.java file is structured as follows:
    • package com.yourpackage.....
    • import io.flutter.embedding.android.FlutterActivity;
    • public class MainActivity extends FlutterActivity { // You can keep this empty class or remove it. }

Don’t forget to update targetSdkVersion and compileSdkVersion to the latest versions, which in this case is 31.

Solution 5: Recreate Android Project

If the error persists, try removing the Android platform from your project and then re-adding it. To do this, follow these steps:

Step 1: Remove Android Platform

Open your terminal or command prompt and navigate to your project directory.

Run the following command to remove the Android platform:

rm -r android

Step 2: Re-add Android Platform

Run the following command to re-add the Android platform:

flutter create --platforms=android .

This will create a new Android project directory. Copy the contents of your old Android directory (such as the app folder and AndroidManifest.xml) into the new Android directory.

Step 3: Rebuild Project

Once you have copied the contents of your old Android directory into the new one, run the following command to rebuild your project:

flutter run

This should build your project successfully without the “Build failed due to use of deprecated Android v1 embedding” error.