[Solved] A splash screen was provided to Flutter, but this is deprecated Error

In this post, we are going to show you how to solve the "A splash screen was provided to Flutter, but this is deprecated" error in Flutter. This error was caused by the AndroidManifest.xml file where the splash screen used to get implemented by default in Flutter App.

W/FlutterActivityAndFragmentDelegate(10040): A splash screen was provided to Flutter, 
but this is deprecated. See flutter.dev/go/android-splash-migration for migration steps.

When you run your app, you may get this message even if you haven't implemented any splash screen on the widget tree. This problem is caused because, in the previous version, Flutter used to implement a splash screen by default on the AndroidManifest.xml file.

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

Open your AndroidManifest.xml file located at android/src/main/AndroidManifest.xml file. Then after, checking it, you will find the <meta-data> mentioned above. This meta tag in the manifest file was included in the previous version of Flutter.

To solve this error, be sure neither io.flutter.embedding.android.SplashScreenDrawable is set in your AndroidManifext.xml file, nor is provideSplashScreen implemented because these android APIs are depreciated after Android version S. You have to remove the following meta tag from the AndrodManifest.xml file:

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

Now, run your app, the error will not appear.

If you still want to go with splash screen, check MainActivity.java or MainActivity.kt file and implement your activity like below:

JAVA:

import android.os.Build;
import android.os.Bundle;
import android.window.SplashScreenView;
import androidx.core.view.WindowCompat;
import io.flutter.embedding.android.FlutterActivity;

public class MainActivity extends FlutterActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // Aligns the Flutter view vertically with the window.
        WindowCompat.setDecorFitsSystemWindows(getWindow(), false);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
            // Disable the Android splash screen fade out animation to avoid
            // a flicker before the similar frame is drawn in Flutter.
            getSplashScreen()
                .setOnExitAnimationListener(
                    (SplashScreenView splashScreenView) -> {
                        splashScreenView.remove();
                    });
        }

        super.onCreate(savedInstanceState);
    }
}

Kotlin:

import android.os.Build
import android.os.Bundle
import androidx.core.view.WindowCompat
import io.flutter.embedding.android.FlutterActivity

class MainActivity : FlutterActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    // Aligns the Flutter view vertically with the window.
    WindowCompat.setDecorFitsSystemWindows(getWindow(), false)

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
      // Disable the Android splash screen fade out animation to avoid
      // a flicker before the similar frame is drawn in Flutter.
      splashScreen.setOnExitAnimationListener { splashScreenView -> splashScreenView.remove() }
    }

    super.onCreate(savedInstanceState)
  }
}

In this way, you can solve the "A splash screen was provided to Flutter, but this is deprecated" Error in Flutter App.

No any Comments on this Article


Please Wait...