apache / cordova-android

Apache Cordova Android
https://cordova.apache.org/
Apache License 2.0
3.65k stars 1.54k forks source link

Splash screen breaks build for SDK lower than v26 #1503

Closed ludovictomlo closed 1 year ago

ludovictomlo commented 2 years ago

Bug Report

Problem

What is expected to happen?

Build should go through successfully.

What does actually happen?

If minSdkVersion is set to 26, there's no issue and the build goes through. However I get the following error if the minSdkVersion is set to lower than 26:

Task :app:processReleaseResources FAILED

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':app:processReleaseResources'. A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction Android resource linking failed ERROR:PATH_TO_APP\platforms\android\app\src\main\res\drawable\ic_cdv_splashscreen.xml: AAPT: error: \<adaptive-icon> elements require a sdk version of at least 26.

Information

I upgraded from cordova-android 10.1.1 to 11.0.0, removed the cordova-plugin-splashscreen since it's been deprecated and updated the implementation to use adaptive icons(generated adaptive icons through Android Studio and moved the .xml files in their place as described), removed old <splash> declarations from the config.xml, added <resource-file> declarations to add the adaptive icons and old splash screens to the /res folder as below.

    <preference name="AndroidWindowSplashScreenAnimatedIcon" value="resources/android/splash-new/mipmap-anydpi-v26/ic_splash.xml" />
    <preference name="AndroidWindowSplashScreenBackground" value="#ffffff" />

    <resource-file src="resources/android/splash-new/values/ic_splash_background.xml" target="app/src/main/res/values/ic_splash_background.xml"/>
    <resource-file src="resources/android/splash-new/mipmap-anydpi-v26/ic_splash.xml" target="app/src/main/res/mipmap-anydpi-v26/ic_splash.xml"/>
    <resource-file src="resources/android/splash-new/mipmap-anydpi-v26/ic_splash_round.xml" target="app/src/main/res/mipmap-anydpi-v26/ic_splash_round.xml"/>
    <resource-file src="resources/android/splash-new/mipmap-hdpi/ic_splash.png" target="app/src/main/res/mipmap-hdpi-v26/ic_splash.png"/>
    <resource-file src="resources/android/splash-new/mipmap-hdpi/ic_splash_round.png" target="app/src/main/res/mipmap-hdpi-v26/ic_splash_round.png"/>
    <resource-file src="resources/android/splash-new/mipmap-hdpi/ic_splash_foreground.png" target="app/src/main/res/mipmap-hdpi-v26/ic_splash_foreground.png"/>
    <resource-file src="resources/android/splash-new/mipmap-mdpi/ic_splash.png" target="app/src/main/res/mipmap-mdpi-v26/ic_splash.png"/>
    <resource-file src="resources/android/splash-new/mipmap-mdpi/ic_splash_round.png" target="app/src/main/res/mipmap-mdpi-v26/ic_splash_round.png"/>
    <resource-file src="resources/android/splash-new/mipmap-mdpi/ic_splash_foreground.png" target="app/src/main/res/mipmap-mdpi-v26/ic_splash_foreground.png"/>
    <resource-file src="resources/android/splash-new/mipmap-xhdpi/ic_splash.png" target="app/src/main/res/mipmap-xhdpi-v26/ic_splash.png"/>
    <resource-file src="resources/android/splash-new/mipmap-xhdpi/ic_splash_round.png" target="app/src/main/res/mipmap-xhdpi-v26/ic_splash_round.png"/>
    <resource-file src="resources/android/splash-new/mipmap-xhdpi/ic_splash_foreground.png" target="app/src/main/res/mipmap-xhdpi-v26/ic_splash_foreground.png"/>
    <resource-file src="resources/android/splash-new/mipmap-xxhdpi/ic_splash.png" target="app/src/main/res/mipmap-xxhdpi-v26/ic_splash.png"/>
    <resource-file src="resources/android/splash-new/mipmap-xxhdpi/ic_splash_round.png" target="app/src/main/res/mipmap-xxhdpi-v26/ic_splash_round.png"/>
    <resource-file src="resources/android/splash-new/mipmap-xxhdpi/ic_splash_foreground.png" target="app/src/main/res/mipmap-xxhdpi-v26/ic_splash_foreground.png"/>
    <resource-file src="resources/android/splash-new/mipmap-xxxhdpi/ic_splash.png" target="app/src/main/res/mipmap-xxxhdpi-v26/ic_splash.png"/>
    <resource-file src="resources/android/splash-new/mipmap-xxxhdpi/ic_splash_round.png" target="app/src/main/res/mipmap-xxxhdpi-v26/ic_splash_round.png"/>
    <resource-file src="resources/android/splash-new/mipmap-xxxhdpi/ic_splash_foreground.png" target="app/src/main/res/mipmap-xxxhdpi-v26/ic_splash_foreground.png"/>
    <resource-file src="resources/android/splash/drawable-land-ldpi-screen.png" target="app/src/main/res/drawable-land-ldpi/screen.png"/>
    <resource-file src="resources/android/splash/drawable-land-mdpi-screen.png" target="app/src/main/res/drawable-land-mdpi/screen.png"/>
    <resource-file src="resources/android/splash/drawable-land-hdpi-screen.png" target="app/src/main/res/drawable-land-hdpi/screen.png"/>
    <resource-file src="resources/android/splash/drawable-land-xhdpi-screen.png" target="app/src/main/res/drawable-land-xhdpi/screen.png"/>
    <resource-file src="resources/android/splash/drawable-land-xxhdpi-screen.png" target="app/src/main/res/drawable-land-xxhdpi/screen.png"/>
    <resource-file src="resources/android/splash/drawable-land-xxxhdpi-screen.png" target="app/src/main/res/drawable-land-xxxhdpi/screen.png"/>
    <resource-file src="resources/android/splash/drawable-port-ldpi-screen.png" target="app/src/main/res/drawable-port-ldpi/screen.png"/>
    <resource-file src="resources/android/splash/drawable-port-mdpi-screen.png" target="app/src/main/res/drawable-port-mdpi/screen.png"/>
    <resource-file src="resources/android/splash/drawable-port-hdpi-screen.png" target="app/src/main/res/drawable-port-hdpi/screen.png"/>
    <resource-file src="resources/android/splash/drawable-port-xhdpi-screen.png" target="app/src/main/res/drawable-port-xhdpi/screen.png"/>
    <resource-file src="resources/android/splash/drawable-port-xxhdpi-screen.png" target="app/src/main/res/drawable-port-xxhdpi/screen.png"/>
    <resource-file src="resources/android/splash/drawable-port-xxxhdpi-screen.png" target="app/src/main/res/drawable-port-xxxhdpi/screen.png"/>

As far as I understood I shouldn't need to move up the minSdkVersion from 22->26, and we wouldn't want to either since it would affect many users. Are there some specific tasks to be done to be able to support the old splashscreens?

Command or Code

$ ionic cordova build android --prod --release

Environment, Platform, Device

Windows 10

Version information

$ ionic info

Ionic:

Ionic CLI : 6.19.0 (C:[REDACTED]\nvm\v16.13.0\node_modules\@ionic\cli) Ionic Framework : @ionic/angular 5.5.5 ([REDACTED]\node_modules\@ionic\angular) @angular-devkit/build-angular : 0.901.15 ([REDACTED]\node_modules\@angular-devkit\build-angular) @angular-devkit/schematics : 9.1.15 ([REDACTED]\node_modules\@angular-devkit\schematics) @angular/cli : 9.1.15 ([REDACTED]\node_modules\@angular\cli) @ionic/angular-toolkit : 2.3.3 ([REDACTED]\node_modules\@ionic\angular-toolkit)

Cordova:

Cordova CLI : 10.0.0 (cordova-lib@10.1.0) Cordova Platforms : android 11.0.0 Cordova Plugins : cordova-clipboard 1.3.0 "Clipboard" cordova-plugin-app-version 0.1.14 "AppVersion" cordova-plugin-apprate 1.7.2 "AppRate" cordova-plugin-device 2.1.0 "Device" cordova-plugin-dialogs 2.0.2 "Notification" cordova-plugin-firebasex 14.2.1 "Google Firebase Plugin" cordova-plugin-inappbrowser 5.0.0 "InAppBrowser" cordova-plugin-ionic-keyboard 2.2.0 "cordova-plugin-ionic-keyboard" cordova-plugin-ionic-webview 5.0.0 "cordova-plugin-ionic-webview" cordova-plugin-nativestorage 2.3.2 "NativeStorage" cordova-plugin-network-information 3.0.0 "Network Information" cordova-plugin-statusbar 3.0.0 "StatusBar" cordova-plugin-taptic-engine 2.2.0 "Taptic Engine" cordova-plugin-x-socialsharing 6.0.4 "SocialSharing" cordova-sqlite-storage 6.0.0 "Cordova SQLite storage plugin - cordova-sqlite-storage plugin version" es6-promise-plugin 4.2.2 "Promise" ionic-plugin-deeplinks 1.0.22 "Ionic Deeplink Plugin" onesignal-cordova-plugin 3.2.0 "OneSignal Push Notifications"

Utility:

cordova-res : 0.15.4 native-run : 1.7.1

System:

Android SDK Tools : 26.1.1 ([REDACTED]\AppData\Local\Android\Sdk) NodeJS : v16.13.0 (C:\Program Files\nodejs\node.exe) npm : 8.1.0 OS : Windows 10

Checklist

breautek commented 1 year ago

I haven't ran into this issue (my min sdk is set to 24), but I'm also using a rastered png instead of vectors...

<preference name="AndroidWindowSplashScreenAnimatedIcon" value="res/android/splash/xxxhdpi.png" />
<preference name="AndroidWindowSplashScreenBackground" value="#6dADDF" />

Based on the error

<adaptive-icon> elements require a sdk version of at least 26.

It seems like using vectors / adaptive icons is what requires API 26

ludovictomlo commented 1 year ago

@breautek hmm, isn't having the adaptive icons with the <preference name="AndroidWindowSplashScreenAnimatedIcon" value="resources/android/splash/mipmap-anydpi-v26/ic_splash.xml"/> a hard requirement for sdk v32 starting 1st of November?

In the release notes it's saying:

We have integrated the Android 12 SplashScreen API including the compatibility library into the core of the Cordova-Android platform to provide support for Android API 22+.

I created the issue ticket because I thought this means that adaptive icons should be possible to use even if the app has a minSdkVersion of 22, but it will just use the generated PNG resources for the correct densities on the lower than v26 versions. Shouldn't this be the case or I just misunderstood the docs?

I'll have to check if I can use the old PNG splash screens as a temporary solution(for the moment I had to drop support for sdk v22-25).

jcesarmobile commented 1 year ago

I can't find anything related to adaptive icons being a requirement, where did you see that?

breautek commented 1 year ago

We have integrated the Android 12 SplashScreen API including the compatibility library into the core of the Cordova-Android platform to provide support for Android API 22+.

This compatibility library is for the splashscreen API not for adaptive icons. I'm not sure if there is a compatibility library for adaptive icons.

The splash screen compatibility library brings the new Android Splashscreen APIs to older Android devices so that the app will have a consistent behavior across older and newer devices.

But I do understand that our current documentation doesn't actually reflect this, and also makes no mention of using rastered images.

Given this is an AAPT error the min SDK 26 requirement might be a hard requirement to use adaptive icons, at least when using the AVD/xml format. I think this needs to be confirmed and our documentation should make this clearer.

I'll have to check if I can use the old PNG splash screens as a temporary solution(for the moment I had to drop support for sdk v22-25).

This will likely not work as the old splashscreens were full screen splashscreens, whereas the new splashscreen is more or less the size of an app logo. But you can pass in a rasterized PNG with a high resolution (suitable for xxxhdpi) and it should appear properly (albeit less efficient) on all screen densities.

ludovictomlo commented 1 year ago

@jcesarmobile I was asking because of this mention, but it doesn't say anything about adaptive icons actually, whoops 😃 image

@breautek I tested and can confirm that by using the xxxhdpi PNG I can get around the min SDK issue and the builds don't throw the AAPT error anymore for minSdkVersion 22. I'll leave in the adaptive icon artifacts until I'll find a solution and will update this issue if I find something. Thanks for the feedback though!

jcesarmobile commented 1 year ago

closing since you solved your issue and was not related to cordova