If you are using Flutter and getting deprecated Android v1 embedding error then it means you are building an older version of your project.
According to Flutter Migration Guide –
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 atio.flutter.embedding.android.FlutterActivity
and associated classes now replace them.
The complete error looks like this –
to migrate your project. You may also pass the --ignore-deprecation flag to .ignore this check and continue with the deprecated v1 embedding. However, the v1 Android embedding will be removed in future versions of Flutter. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ The detected reason was: C:\Users\akash\OneDrive\Desktop\Project\myapp\app\android\app\src\main\AndroidManifest.xml uses `android:name="io.flutter.app.FutterApplication"` ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Build failed due to use of deprecated Android v1 embedding.
Solution
The migration is a 2 step process –
Step 1: Replace io.flutter.app.FlutterActivity
by io.flutter.embedding.android.FlutterActivity
in MainActivity.java
.
Open android/app/src/main/java/[your/package/name]/MainActivity.java and confirm that it should look like this –
import io.flutter.embedding.android.FlutterActivity; public class MainActivity extends FlutterActivity { }
Or, if there is content in MainActivity
, then it should look like this –
import androidx.annotation.NonNull; import io.flutter.embedding.android.FlutterActivity; import io.flutter.embedding.engine.FlutterEngine; import io.flutter.plugin.common.MethodChannel; import io.flutter.plugins.GeneratedPluginRegistrant; public class MainActivity extends FlutterActivity { private static final String CHANNEL = "samples.flutter.dev/battery"; @Override public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { GeneratedPluginRegistrant.registerWith(flutterEngine); new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL) .setMethodCallHandler( (call, result) -> { // Your existing code } ); } }
Step 2: Open android/app/src/main/AndroidManifest.xml
a. Replace android:name="io.flutter.app.FlutterApplication"
with android:name="${applicationName}"
.
<application <!-- Replace the below line 👇 --> <!-- android:name="io.flutter.app.FlutterApplication" --> android:name="${applicationName}" <!-- With this ☝️ --> > <!-- Other code --> </application>
b. Add meta-tag
in <application>
tag –
<application android:name="${applicationName}" > <meta-data android:name="flutterEmbedding" android:value="2" /> <!-- ☝️ Add this meta tag --> </application>
These steps will solve the build failed issue and your app will run successfully.