cordova-android: Cordova 11.0.0 + Android 11.0.0 - cordova prepare android --debug command fails
Bug Report
Using Cordova 11 and Android 11.0.0, the cordova prepare android --debug
command fails with:
The "AndroidWindowSplashScreenAnimatedIcon" is undefined. Cordova's default will be used.
Cannot set properties of null (setting 'text')
TypeError: Cannot set properties of null (setting 'text')
at updateProjectSplashScreenBackgroundColor (C:\iizi\iiziRunDevel\node_modules\cordova-android\lib\prepare.js:484:68)
at C:\iizi\iiziRunDevel\node_modules\cordova-android\lib\prepare.js:392:13
at Array.forEach (<anonymous>)
at updateProjectSplashScreen (C:\iizi\iiziRunDevel\node_modules\cordova-android\lib\prepare.js:384:7)
at updateProjectAccordingTo (C:\iizi\iiziRunDevel\node_modules\cordova-android\lib\prepare.js:269:5)
at C:\iizi\iiziRunDevel\node_modules\cordova-android\lib\prepare.js:67:21
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Promise.all (index 0)
Problem
We do not want to display a splash screen at all, and the only way to do so is to include the cordova-plugin-spashscreen
and then turn it off using <preference name="SplashScreen" value="none"/>
. Please note that we don’t provide any splash screen assets.
What is expected to happen?
The production of the prepared Android Cordova build. When using Cordova Android 10.1.2 it worked fine.
What does actually happen?
Cordova Prepare fails with the verbose output:
Wrote out android application name "Develop" to C:\iizi\iiziRunDevel\platforms\android\app\src\main\res\values\strings.xml
The "AndroidWindowSplashScreenAnimatedIcon" is undefined. Cordova's default will be used.
Cannot set properties of null (setting 'text')
TypeError: Cannot set properties of null (setting 'text')
at updateProjectSplashScreenBackgroundColor (C:\iizi\iiziRunDevel\node_modules\cordova-android\lib\prepare.js:484:68)
at C:\iizi\iiziRunDevel\node_modules\cordova-android\lib\prepare.js:392:13
at Array.forEach (<anonymous>)
at updateProjectSplashScreen (C:\iizi\iiziRunDevel\node_modules\cordova-android\lib\prepare.js:384:7)
at updateProjectAccordingTo (C:\iizi\iiziRunDevel\node_modules\cordova-android\lib\prepare.js:269:5)
at C:\iizi\iiziRunDevel\node_modules\cordova-android\lib\prepare.js:67:21
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Promise.all (index 0)
Information
The config.xml file:
<widget xmlns="http://www.w3.org/ns/widgets"
xmlns:cdv="http://cordova.apache.org/ns/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
version = "1.0.0"
android-versionCode = "10000"
defaultlocale = "en-US"
id = "com.some.prod"
android-packageName = "com.some.prod">
<name>Product Name</name>
<description>Description</description>
<author email="some@email.com" href="https://somewhere.com">Some Company Name</author>
<!-- "~11.0.0" fails, but "10.1.2" is working-->
<engine name="android" spec="11.0.0" />
<plugin name="cordova-plugin-proguard" spec="~2.2.0" />
<preference name="PreferredContentMode" value="mobile" />
<preference name="AndroidPersistentFileLocation" value="Internal"/>
<preference name="AndroidXEnabled" value="true" />
<preference name="android-minSdkVersion" value="22" />
<preference name="android-targetSdkVersion" value="33" />
<config-file target="config.xml" parent="/*">
<preference name="GradlePluginGoogleServicesEnabled" value="true" />
</config-file>
<plugin name="cordova-plugin-splashscreen" spec="~6.0.2" />
<plugin name="cordova-plugin-battery-status" spec="~2.0.3" />
<plugin name="cordova-plugin-network-information" spec="~3.0.0" />
<plugin name="cordova-plugin-statusbar" spec="~3.0.0" />
<plugin name="cordova-plugin-vibration" spec="~3.1.1" />
<plugin name="cordova-plugin-file" spec="~7.0.0" />
<plugin name="cordova-plugin-camera" spec="~6.0.0" />
<plugin name="cordova-plugin-device" spec="~2.1.0" />
<feature name="Device">
<param name="android-package" value="org.apache.cordova.device.Device" />
</feature>
<plugin name="cordova-plugin-dialogs" spec="~2.0.2" />
<plugin name="cordova-plugin-geolocation" spec="~4.1.0" />
<plugin name="cordova-plugin-inappbrowser" spec="~5.0.0" />
<plugin name="cordova-plugin-media" spec="~6.0.0">
<variable name="KEEP_AVAUDIOSESSION_ALWAYS_ACTIVE" value="YES" />
</plugin>
<plugin name="cordova-plugin-media-capture" spec="~4.0.0" />
<plugin name="cordova-plugin-screen-orientation" spec="~3.0.2" />
<plugin name="cordova-plugin-customurlscheme" spec="~5.0.2" >
<variable name="URL_SCHEME" value="iizirundev" />
</plugin>
<plugin name="cordova-plugin-fingerprint-aio" spec="~5.0.1">
<variable name="FACEID_USAGE_DESCRIPTION" value="For Face ID authentication" />
</plugin>
<plugin name="phonegap-plugin-barcodescanner" spec="~8.1.0">
<variable name="ANDROID_SUPPORT_V4_VERSION" value="24.1.0" />
</plugin>
<plugin name="wifiwizard2" spec="~3.1.1" />
<plugin name="cordova-plugin-flashlight" spec="~3.2.0" />
<plugin name="cordova-plugin-firebasex" spec="~14.1.0" >
<variable name="FIREBASE_ANALYTICS_COLLECTION_ENABLED" value="true" />
<variable name="FIREBASE_PERFORMANCE_COLLECTION_ENABLED" value="true" />
<variable name="FIREBASE_CRASHLYTICS_COLLECTION_ENABLED" value="true" />
<variable name="IOS_ENABLE_CRITICAL_ALERTS_ENABLED" value="false" />
</plugin>
<allow-intent href="iizirundev:*" />
<allow-intent href="http:*" />
<allow-intent href="https:*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<allow-intent href="maps:*" />
<allow-intent href="comgooglemaps:*" />
<allow-intent href="facetime:*" />
<allow-intent href="fb:*" />
<allow-intent href="whatsapp:*" />
<allow-intent href="twitter:*" />
<allow-intent href="pinterest:*" />
<allow-intent href="instagram:*" />
<allow-intent href="vnd.youtube:*" />
<allow-intent href="yelp:*" />
<allow-intent href="linkedin:*" />
<allow-intent href="snapchat:*" />
<allow-intent href="tumblr:*" />
<access origin="*" />
<access origin="cdvfile://*" />
<access origin="https://tel:*" launch-external="yes" />
<access origin="https://sms:*" launch-external="yes" />
<access origin="https://mailto:*" launch-external="yes" />
<access origin="https://geo:*" launch-external="yes" />
<access origin="https://facetime:*" launch-external="yes" />
<access origin="https://maps:*" launch-external="yes" />
<access origin="https://comgooglemaps:*" launch-external="yes" />
<preference name="SplashScreen" value="none" />
<preference name="AutoHideSplashScreen" value="false" />
<preference name="ShowSplashScreenSpinner" value="false" />
<preference name="FadeSplashScreen" value="false" />
<preference name="FadeSplashScreenDuration" value="0" /> <!-- 350 -->
<preference name="SplashScreenDelay" value="0" /> <!-- 3000 -->
<preference name="SplashMaintainAspectRatio" value="true" />
<preference name="SplashShowOnlyFirstTime" value="true" /> <!-- false -->
<preference name="SplashScreenBackgroundColor" value="#000000" /> <!-- Black background -->
<preference name="DisallowOverscroll" value="true" />
<preference name="KeyboardDisplayRequiresUserAction" value="false" />
<preference name="SuppressesLongPressGesture" value="true" />
<preference name="Suppresses3DTouchGesture" value="true" />
<preference name="CameraUsesGeolocation" value="true" />
<platform name="android">
<content src="http://localhost/index.html" />
<allow-intent href="market:*" />
<preference name="android-manifest/application/activity/@android:windowSoftInputMode" value="adjustPan" />
<config-file target="AndroidManifest.xml" parent="./application" mode="replace">
<meta-data android:name="android.max_aspect" android:value="5.0"/>
</config-file>
<edit-config file="app/src/main/AndroidManifest.xml" mode="merge" target="/manifest/application">
<application android:usesCleartextTraffic="true" />
</edit-config>
<icon src="icons/android/96.png" />
<resource-file src="icons/android/adaptive/bgcolor.xml" target="/app/src/main/res/values/colors.xml"/>
<icon src="icons/android/36.png" density="ldpi" foreground="icons/android/adaptive/f48.png" background="@color/background" />
<icon src="icons/android/48.png" density="mdpi" foreground="icons/android/adaptive/f64.png" background="@color/background" />
<icon src="icons/android/72.png" density="hdpi" foreground="icons/android/adaptive/f96.png" background="@color/background" />
<icon src="icons/android/96.png" density="xhdpi" foreground="icons/android/adaptive/f128.png" background="@color/background" />
<icon src="icons/android/144.png" density="xxhdpi" foreground="icons/android/adaptive/f192.png" background="@color/background" />
<icon src="icons/android/192.png" density="xxxhdpi" foreground="icons/android/adaptive/f256.png" background="@color/background" />
</platform>
</widget>
The part with all the icons could probably be left out for testing. As you can see, there are no provided spash screens.
Source code of C:\iizi\iiziRunDevel\node_modules\cordova-android\lib\prepare.js:484:68
:
/**
* @param {String} splashBackgroundColor SplashScreen Background Color Hex Code
* be used to update project
* @param {Object} locations A map of locations for this platform
*/
function updateProjectSplashScreenBackgroundColor (splashBackgroundColor, locations) {
if (!splashBackgroundColor) { splashBackgroundColor = '#FFFFFF'; }
// res/values/colors.xml
const colors = xmlHelpers.parseElementtreeSync(locations.colors);
/* Line 484 */ colors.find('color[@name="cdv_splashscreen_background"]').text = splashBackgroundColor.replace(/'/g, '\\\'');
fs.writeFileSync(locations.colors, colors.write({ indent: 4 }), 'utf-8');
events.emit('verbose', 'Wrote out Android application SplashScreen Color to ' + locations.colors);
}
If I edit the source code to include the following line before line 484:
if ( colors.find('color[@name="cdv_splashscreen_background"]') )
The prepare command works a little bit longer but fails as show below, and I don’t know the side-effects.
Checking Java JDK and Android SDK versions
ANDROID_HOME=C:\iiziBuildInstall\windows\android (recommended setting)
ANDROID_SDK_ROOT=C:\iiziBuildInstall\windows\android (DEPRECATED)
Using Android SDK: C:\iiziBuildInstall\windows\android
Reading build config file: C:\iizi\iiziRunDevel\build.json
Reading the keystore from: C:\iizi\iiziRunDevel\nexum.keystore
Starting a Gradle Daemon (subsequent builds will be faster)
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.4.2/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 15s
1 actionable task: 1 executed
Subproject Path: CordovaLib
Subproject Path: app
Gradle Distribution URL: https://services.gradle.org/distributions/gradle-7.4.2-all.zip
FAILURE: Build failed with an exception.
* Where:
Script 'C:\iizi\iiziRunDevel\platforms\android\CordovaLib\cordova.gradle' line: 165
* What went wrong:
A problem occurred evaluating script.
> For input string: "android-33"
* 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
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.4.2/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 1s
Command failed with exit code 1: C:\iizi\iiziRunDevel\platforms\android\gradlew cdvBuildDebug -b C:\iizi\iiziRunDevel\platforms\android\build.gradle
Error: Command failed with exit code 1: C:\iizi\iiziRunDevel\platforms\android\gradlew cdvBuildDebug -b C:\iizi\iiziRunDevel\platforms\android\build.gradle
at makeError (C:\iizi\iiziRunDevel\node_modules\execa\lib\error.js:60:11)
at handlePromise (C:\iizi\iiziRunDevel\node_modules\execa\index.js:118:26)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async ProjectBuilder.build (C:\iizi\iiziRunDevel\node_modules\cordova-android\lib\builders\ProjectBuilder.js:330:20)
Command or Code
cordova prepare android --debug
Environment, Platform, Device
Windows 11, Node v16.16.0, Cordova 11.0.0, Android 11.0.0.
Version information
npm info cordova
cordova@11.0.0 | Apache-2.0 | deps: 13 | versions: 1887
Cordova command line interface tool
keywords: cordova, client, cli
bin: cordova
dist
.tarball: https://registry.npmjs.org/cordova/-/cordova-11.0.0.tgz
.shasum: c7a4bf853a55652aa293d20299a6c92ba3a22af1
.integrity: sha512-Hu2YeT0naeP/1sEm/xfJYUsXN48XV6zagxbi1+4q0Ei9c5TKsIq8v4EWukvSHF4UO2pnh+9ViaDlGMcS1Wrnfg==
.unpackedSize: 144.3 kB
dependencies:
configstore: ^5.0.1 editor: ^1.0.0 loud-rejection: ^2.2.0 update-notifier: ^5.1.0
cordova-common: ^4.0.2 execa: ^5.1.1 nopt: ^5.0.0
cordova-create: ^4.0.0 fs-extra: ^10.0.0 semver: ^7.3.5
cordova-lib: ^11.0.0 insight: ^0.11.1 systeminformation: ^5.9.17
dist-tags:
3.6.0-0.2.8: 3.6.0-0.2.8 nightly: 11.0.1-nightly.2022.7.18.6cf1e36c
latest: 11.0.0 rc: 5.3.3
Checklist
- I searched for existing GitHub issues
- I updated all Cordova tooling to most recent version
- I included all the necessary information above
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 23 (6 by maintainers)
Sorry, I missed this on my first time reading your ticket. Not providing any splashscreen at all is simply not possible. Android now enforces the splashscreen on Android 12 or later. On older versions of Cordova, you would see the Android splashscreen, as well as the cordova custom splashscreen (which could have been disabled) if you run your app on Android 12 devices. This is behaviour that cannot be changed. Android Docs highlights some unintended consequences if you do not migrate to the new splashscreen system, which cordova-android@11 implements.
In cordova-android@11, to make the Android 12 splashscreen backwards compatible, it includes a compatibility library that implements the Android 12 splashscreens on older devices. This library is provided by Google. cordova-android@11 does not support
cordova-plugin-splashscreen
and that plugin is now obsolete.Hi, as previously stated, I try the migration to Cordova Android 11. I had exactly the same error. However, with the analysis above, I quickly fixed the build. We add a
after_prepare
script that overwrites thecolors.xml
of Cordova by ours. Once disabled, it worked fine. As Android mentioned it, the filename “res/values/colors.xml” is arbitrary ; thus you can rename it to whatever and it’ll work (ie: colors-custom.xml) (if someone can confirm, will be great). Kr.@scyclops Thank you for pointing out the docs you followed that caused this issue.
Before Cordova-Android 11 the
colors.xml
file did not exist and was added to support the new SplashScreen requirements from Android.This line will now cause issues as it will overwrite the exisiting
colors.xml
file. I believe you can rename your colors file to something else and Android build it should pick it up automatticly.E.g.
You can keep whatever you have now in the
src
value, or rename if desired, but the target is the important part that should chanmge to avoid conflicts.You might also be able to use
config-file
to add elements to the exisitingcolors.xml
instead of uploading a file, but it might be better create new xml files instead. There were some reports where even plugins overwritten thecolors.xml
file.I will take a look in updating the documentation.
FWIW - I ran into this problem because the Cordova Android documentation at the link below explicitly says to create a res/values/colors.xml file for adaptive icons with colors and doing that triggers this error when upgrading to Cordova 11. The documentation at the link below should probably be updated to recommend a different file name if no other fix is being worked on for this issue.
https://cordova.apache.org/docs/en/11.x/config_ref/images.html#adaptive-icon-with-colors
cordova-plugin-splashscreen@6.0.2 is and has been released. It’s been updated so it doesn’t install on cordova-android@11 so it doesn’t cause conflicts, particularly if you still require it because you develop for other platforms.
I think Erisu clearly stated what is new and valid for cordova-android@11 moving forward is documented. And like he mentioned, some preferences when applicable, was carried over from the older splashscreen plugin, which are also documented.
This is a nature of any plugin system. Yes it’s an issue but not necessarily within Cordova codebase. From what I understand reading this thread, there are two occurrences where this happens.
If you’re manually managing/overriding the colors.xml` file which the core platform now depends on. Then you’ll need t re-implement everything that Cordova does to manage this file to support all the features that Cordova has around this file. This isn’t a bug with Cordova.
It is possible that plugins have defined their own colors.xml because they have their own native UIs. If they are overwriting Cordova’s colors.xml, that will make plugins incompatible with cordova-android@11. They’ll have to be updated to use <config-file to append to the file, or <edit-config> if they require to edit an existing node.
As with all major releases, there is potential for breaking changes. In this specific case there is incompatibility with cordova-android@11 and firebasex due to a configuration conflict. But this doesn’t make it a bug.
~I would suggest to raise an issue against firebasex maintainers if there isn’t one already to let them know that there is a configuration conflict.~
Edit: I just tested
cordova-plugin-firebasex@14.2.0
against the current release of cordova-android and it properly updatescolors.xml
to append<color name="accent">#FF00FFFF</color>
instead of overwriting it. Preparing/building also appears to work, the build fails purely because I don’t actually have google-services.json to provide credentials/API keys.You should not install
cordova-plugin-spashscreen
with Cordova-Android 11, in factcordova-plugin-spashscreen@6.0.2
will not install for Cordova-Android 11. The next major release ofcordova-plugin-spashscreen
will actually delete all of the source code for Android.Also the preference only controlled the
cordova-plugin-spashscreen
’s SplashScreen.As @breautek pointed out
It also includes Googles design requirements, and for Cordova-Android to continue to support older devices with consistency, the compatibility library was added. This means the SplashScreen will be displayed for API 22+, no option to turn off.
As for the error, maybe try deleting the entire
platforms
directory and then runcordova prepare
so it can recreate the entire directory from scratch. I noticedcordova-plugin-firebasex
also has acolors.xml
file with no values. It might be overwritting the file and therefore it cant find the key. Try uninstalling the plugin temporarily to confirm.