Does capacitor work with the new Android 12 SplashScreen API?

I have an Ionic/Capacitor app that targets Android. As recommended by the Capacitor documentation, my app uses the cordova-res package to generate the splash screen.

The cordova-res splash screen worked until I recently upgraded to the latest AndroidStudio Dolphin 2021.3.1. Now, instead of displaying the splash screen located in the ./resources/splash.png file, it simply displays my app’s icon located in the ./resources/android/icon-foreground.png.

After some research, it seems like this is the default behavior for Android 12 (and later) new SplashScreen API requirement. It is documented here: Splash screens  |  Android Developers. According to this document, the default behavior is for Android to display the app’s icon if you don’t have a splash screen.

I’m wondering if cordova-res and capacitor simply is broken now, because of the new SplashScreen API introduced in Android 12.

Is there any way to force Android Studio to go back to the old way of showing splash screens, which works fine with cordova-res and capacitor?

Is there any plan for capacitor and cordova-res to support the new Android SplashScreen API?

1 Like

You can try to use GitHub - ionic-team/capacitor-assets: Local Capacitor icon/splash screen resource generation tool

I had a lot of problems when I upgraded my app to the latest Ionic and Capacitor versions… It took me a while to figure it out how to correctly show the splash screen.

Cordova-res still works, in a way, but you need some configuration in your theme.

<style name="AppTheme.NoActionBarLaunch" parent="Theme.SplashScreen">
       <item name="android:background">@drawable/splash</item>
       <!-- <item name="android:windowBackground">@drawable/splash</item> -->
       <item name="android:windowSplashScreenBackground" tools:targetApi="s">@color/colorPrimary</item>

       // Set this to the single background color of the splash screen.
       // If you want to change the background color in dark mode, create
       // a night version of the color.
       <item name="windowSplashScreenBackground">@color/colorPrimary</item>

       // Set this to a VectorDrawable. On API 31+ it may animated,
       // in which case it will be animated during launch.
       // See
       // for info on size limits.
       <item name="windowSplashScreenAnimatedIcon">@drawable/splash</item>

       <item name="postSplashScreenTheme">@style/AppTheme.NoActionBar</item>