question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cordova 11.0.0 + Android 11.0.0 - cordova prepare android --debug command fails

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
TiBz0ucommented, Aug 18, 2022

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 the colors.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.

1reaction
breautekcommented, Jul 22, 2022

Is there a rough “release date” for this new plugin?

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.

At least provide SOME lead as to which setting is valid in the NEW Android-11 version and which ones do no longer apply.

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.

The prepare stage should not throw a null pointer – it’s that simple. It’s a bug

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.

In our case, this issue was resolved by either omitting the line <resource-file src="icons/android/adaptive/bgcolor.xml" target="/app/src/main/res/values/colors.xml"/>.

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.

An interesting thing is however happening when the Android platform is added with our config.xml file, perhaps because we use the plugin cordova-plugin-firebasex@14.2.0 with its plugins\cordova-plugin-firebasex\src\android\src\android\colors.xml

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 updates colors.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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[GitHub] [cordova-android] minduch commented on issue #1461
[GitHub] [cordova-android] minduch commented on issue #1461: Cordova 11.0.0 + Android 11.0.0 - cordova prepare android --debug command fails.
Read more >
Android Platform Guide - Apache Cordova
This guide will help set up your development environment for building Cordova apps for Android devices and optionally use Android-specific command-line ...
Read more >
Cordova Android 11 Build Error - Ionic Forum
Hello, I have upgraded cordova-android of my ionic 6 project from 10.1.2 to 11.0.0 using below commands as shown in this cordova's official ......
Read more >
The command "cordova platform add Android --save" doesn't ...
As a result, a 404 error is displayed. kuniatsu$ ionic cordova build Android ? Platform Android is not installed! Would you like to...
Read more >
Failing to add cordova plugin from Github - Builds
Bringing back the joy of iOS & Android development through automating build, testing and support cycles. Relevant log extract from the Ionic Archive...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found