'Flutter: To avoid unexpected runtime failures, or future build failures, try to see if these plugins support the Android V2 embedding

So I upgraded my Flutter version to "2.5.3" and since then my code stop running and when I run it I get the error that says: The plugins `flutter_custom_dialog, flutter_webview_plugin, libphonenumber, permission, shared_preferences, simple_rsa, url_launcher` use a deprecated version of the Android embedding. To avoid unexpected runtime failures, or future build failures, try to see if these plugins support the Android V2 embedding. Otherwise, consider removing them since a future release of Flutter will remove these deprecated APIs. If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration. And then the run will stop and I will get further error like 146:15: Error: The method 'setMockMethodCallHandler' isn't defined for the class 'MethodChannel'. and with addition below error: ``` FAILURE: Build failed with an exception.

  • Where: Script '/Users/mickeymuller/Downloads/fluttersdk/packages/flutter_tools/gradle/flutter.gradle' line: 1005

  • What went wrong: Execution failed for task ':app:compileFlutterBuildDebug'.

Process 'command '/Users/mickeymuller/Downloads/fluttersdk/bin/flutter'' finished with non-zero exit value 1

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 4m 31s Exception: Gradle task assembleDebug failed with exit code 1 ```



Solution 1:[1]

You may already have found your answer,still I provide a solution for this problem for others, who might have the same problem.

If you don't have added code to android/app/src/main/java/[your/package/name]/MainActivity.java

  1. Go to android/app/src/main/java/co/<XXXX>/<YYYY>/MainActivity.java

  2. remove all of the imports

  3. add the following line to the imports:

    import io.flutter.embedding.android.FlutterActivity;

  4. delete all of the contents inside the MainActivity Block, so your file looks like this:

    import io.flutter.embedding.android.FlutterActivity; public class MainActivity extends FlutterActivity {}

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

  6. replace android:name with android:name="${applicationName}"

  7. Remove all <meta-data> tags with key android:name="io.flutter.app.android.SplashScreenUntilFirstFrame".

  8. Add the following above the <intent-filter> the following code:

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

    <meta-data android:name="io.flutter.embedding.android.SplashScreenDrawable" android:resource="@drawable/launch_background" />

  9. try to build your app

If you have added code to the mainActivity.java or want to know more about it visit this post which is also the source of my solution. There's also a nice youtube video demonstrating this solution, you can watch it here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mOOn