apache / cordova-android

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

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

Open minduch opened 1 year ago

minduch commented 1 year ago

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

minduch commented 1 year ago

How to use the latest 11.0.1-dev (2) (or later) version(s) from github in my builds?

  1. cordova platform add android@10.1.2 (today working, 11.0.0 doesn't work)
  2. config.xml definition of that version, today <engine name="android" spec="10.1.2"/>

Thanks in advance.

breautek commented 1 year ago

If you want install a development build, you have to use the github repo url.

e.g. cordova platform add https://github.com/apache/cordova-android.git

Which will install the main branch. NPM also supports #<commit-ish> to install from a git repository at a specific commit, branch, or tag.

Alternatively, you can cordova platform add android@nightly which will use a nightly published version based on the main branch, which should contain changes that was pushed at least 24 hours ago.

The prepare command works a little bit longer but fails as show below, and I don't know the side-effects.

Based on the output:

  • What went wrong: A problem occurred evaluating script. For input string: "android-33"

The issue appears to be related to using target SDK 33, which is an SDK level that Cordova might not support yet. cordova-android@11 adds support for SDK levels that was available during the time of development, which was up to SDK 32.

Try removing <preference name="android-targetSdkVersion" value="33" /> or setting it's value to 32 to see if it creates a difference in behaviour. Cordova's default target SDK is 32 in cordova-android@11 when the android-targetSdkVersion is not supplied.

minduch commented 1 year ago

I changed Android SDK from 33 to 32. I tried all combinations of cordova-android 11.0.0 (@latest), @nightly and the one from github (failed dramatically with node). None works, I still get the same error.

The major problem is in the function updateProjectSplashScreenBackgroundColor in the source C:\iizi\iiziRunDevel\node_modules\cordova-android\lib\prepare.js:484:68 where colors.find('color[@name="cdv_splashscreen_background"]') returns null.

Then I don't know about the other problems...

minduch commented 1 year ago

Is there a possible work-around to set some variable or parameter in config.xml (e.g. cdv_splashscreen_backup)?

breautek commented 1 year ago

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 . Please note that we don't provide any splash screen assets.

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.

minduch commented 1 year ago

Well, I know this, but we just have not specified any splash screens at all in config.xml. Then the default Cordova ones are always used, unless we set it to display "none". The app logo is shown on startup on black color using Cordova Android 10.1.2 under Android 12+ (and this is fine). But for Cordova Android 11.0.0, the project cannot be "cordova prepare"'ed. THAT IS THE PROBLEM.

Then for the documentation you refer to: it is pure Android and is not specific for Cordova. Is there any doc available for how to define all this for Android in config.xml for Cordova Android 11.0.0?

erisu commented 1 year ago

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"/>.

You should not install cordova-plugin-spashscreen with Cordova-Android 11, in fact cordova-plugin-spashscreen@6.0.2 will not install for Cordova-Android 11. The next major release of cordova-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

Android now enforces the splashscreen on Android 12 or later.

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 run cordova prepare so it can recreate the entire directory from scratch. I noticed cordova-plugin-firebasex also has a colors.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.

teranpeterson commented 1 year ago

I am experiencing this same error as well. I've uninstalled the cordova-plugins-splashscreen plugin and removed all associated preference and splash tags from my config. All I have now is the new preference key <preference name="AndroidWindowSplashScreenAnimatedIcon" value="path/to/png/file" />. Can't get cordova to prepare or even add android as a platform.

Side note: Could we get a migration guide of some kind? This took some serious reading of release notes to figure out.

minduch commented 1 year ago

I have done some further investigation as to why our project fails performing the cordova prepare command when using cordova-android@11.0.0. In a new directory, just for testing, I executed the following steps:

  1. cordova create TestApp
  2. cd TestApp
  3. cordova platform add android@latest

A new file is generated by the cordova-android@11.0.0 plugin, namely platforms\android\app\src\main\res\values\colors.xml with the contents (originating from node_modules\cordova-android\templates\project\res\values\colors.xml):

<?xml version='1.0' encoding='utf-8'?>
<resources xmlns:tools="http://schemas.android.com/tools">
    <color name="cdv_splashscreen_background">#FFFFFF</color>
</resources>

When looking at our config.xml file, there is a block of lines for the (adaptive) icons:

  <!-- Android adaptive icons with fallback -->
  <resource-file src="icons/android/adaptive/bgcolor.xml" target="/app/src/main/res/values/colors.xml"/> <!-- Background color - not image -->

  <!-- Adaptive icons are 108 dp (display pixels) with a "border" of 18 on each side (= 36 reserved by the system), for image size 2048 dp, it gives a bleed of 341.333333333 dp -->
  <icon src="icons/android/36.png"  density="ldpi"    foreground="icons/android/adaptive/f48.png"  background="@color/background" /> <!--  36 - 12 (2x 6) -  48 -->
  <icon src="icons/android/48.png"  density="mdpi"    foreground="icons/android/adaptive/f64.png"  background="@color/background" /> <!--  48 - 16 (2x 8) -  64 -->
  <icon src="icons/android/72.png"  density="hdpi"    foreground="icons/android/adaptive/f96.png"  background="@color/background" /> <!--  72 - 24 (2x12) -  96 -->
  <icon src="icons/android/96.png"  density="xhdpi"   foreground="icons/android/adaptive/f128.png" background="@color/background" /> <!--  96 - 32 (2x16) - 128 -->
  <icon src="icons/android/144.png" density="xxhdpi"  foreground="icons/android/adaptive/f192.png" background="@color/background" /> <!-- 144 - 48 (2x24) - 192 -->
  <icon src="icons/android/192.png" density="xxxhdpi" foreground="icons/android/adaptive/f256.png" background="@color/background" /> <!-- 192 - 64 (2x32) - 256 -->

When removing the line <resource-file src="icons/android/adaptive/bgcolor.xml" target="/app/src/main/res/values/colors.xml"/>, the cordova prepare command worked just fine, and the project could then begin to build and the problem was solved.

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:

<?xml version="1.0" encoding="utf-8"?>
<resources>
</resources>

and the fact that we have some specifications for the splash screen that is now deprecated:

<!-- Splash screen -->
<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 -->

leaves us with the mystery below.

Once our Android platform is generated from an existing config.xml file (specified in the first entry in this issue) using cordova platform add android@latest, the file platforms\android\app\src\main\res\values\colors.xml is generated:

<?xml version='1.0' encoding='utf-8'?>
<resources xmlns:tools="http://schemas.android.com/tools">
    <color name="cdv_splashscreen_background">#FFFFFF</color>
    <color name="accent">#FF00FFFF</color>
</resources>

For some reason, the XML schema specification xmlns:tools="http://schemas.android.com/tools" is added to the resources tag along with the accent color as <color name="accent">#FF00FFFF</color>.

We have NO CLUE as to from where the accent color definition comes from.

So PLEASE: can Cordova provide better documentation for the Android platform as to regarding the specifics to define the <color name="cdv_splashscreen_background">#FFFFFF</color> using some "preference" setting or what not.

Then how does one add just a new color definition, in our case the background color for our adaptive icons as the current Cordova documentation example suggests to do, i.e. to specify the icons as we did with a background color:

<!-- Android adaptive icons with fallback -->
<resource-file src="icons/android/adaptive/bgcolor.xml" target="/app/src/main/res/values/colors.xml"/> <!-- Background color for adaptive icons - not using images -->

<!-- Adaptive icons are 108 dp (display pixels) with a "border" of 18 on each side (= 36 reserved by the system), for image size 2048 dp, it gives a bleed of 341.333333333 dp -->
<icon src="icons/android/36.png"  density="ldpi"    foreground="icons/android/adaptive/f48.png"  background="@color/background" /> <!--  36 - 12 (2x 6) -  48 -->
<icon src="icons/android/48.png"  density="mdpi"    foreground="icons/android/adaptive/f64.png"  background="@color/background" /> <!--  48 - 16 (2x 8) -  64 -->
<icon src="icons/android/72.png"  density="hdpi"    foreground="icons/android/adaptive/f96.png"  background="@color/background" /> <!--  72 - 24 (2x12) -  96 -->
<icon src="icons/android/96.png"  density="xhdpi"   foreground="icons/android/adaptive/f128.png" background="@color/background" /> <!--  96 - 32 (2x16) - 128 -->
<icon src="icons/android/144.png" density="xxhdpi"  foreground="icons/android/adaptive/f192.png" background="@color/background" /> <!-- 144 - 48 (2x24) - 192 -->
<icon src="icons/android/192.png" density="xxxhdpi" foreground="icons/android/adaptive/f256.png" background="@color/background" /> <!-- 192 - 64 (2x32) - 256 -->

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"/>. Then again, in order to get our background colors, the accent color and the cdv_splashscreen_background, we changed our icons/android/adaptive/bgcolor.xml file instead of omitting the line that overwrites colors.xml to contain:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
  <color name="cdv_splashscreen_background">#FFFFFF</color>
  <color name="accent">#FF00FFFF</color>
  <color name="background">#664c88</color>
</resources>

_After this, the issue was resolved, but we still do not understand how to define these two colors (and perhaps other things), specific to Cordova Android 11+, such as the colors accentand cdv_splashscreen_background._

minduch commented 1 year ago

You should not install cordova-plugin-spashscreen with Cordova-Android 11, in fact cordova-plugin-spashscreen@6.0.2 will not install for Cordova-Android 11. The next major release of cordova-plugin-spashscreen will actually delete all of the source code for Android.

Also the preference only controlled the cordova-plugin-spashscreen's SplashScreen.

Is there a rough "release date" for this new plugin?

Request for Documentation

Please add documentation for the Cordova-specifics for cordova-android@11.x regarding the splash screens and the colors, it is not sufficient to just link to Google Android sites when the config.xml file is the only thing that really works well for Cordova Android projects.

erisu commented 1 year ago

We do not add accent to the colors.xml file.

You are most likely installing some plugin that is updating the colors.xml file.

Also, see Cordova's Core Feature SplashScreen Documentation on how to configure the SplashScreen.

Everything that is needed to know is defined there.

https://cordova.apache.org/docs/en/11.x/core/features/splashscreen/index.html

It does not explicitly say what sets cdv_splashscreen_background because it is an internal variable...

Most Cordova developers just want to know how to change the Background Color, which there is a preference called AndroidWindowSplashScreenBackground that does so.

If we documented every internal variable then the documentation would most likely become unreadable or information overload.

You might want to start by reading the documentation.

And no, not all of those preferences were deprecated and removed. We tried to keep those that were still valid and able to be used. Again its in the documentation linked above.

minduch commented 1 year ago

Well, @erisu, I have read that documentation quite well. And it's almost impossible to understand what we have done wrong with the cdv_splashscreen_background to cause the cordova prepare command for Android to fail. Then you also say in Cordova-Android-11 that it is deprecated and should not be installed because it is integrated. At least provide SOME lead as to which setting is valid in the NEW Android-11 version and which ones do no longer apply. It shouldn't clutter up the documentation more than it already is.

I think the issue is the failure of prepare for Android@11 platform, and that should be fixed so that it doesn't produce a null exception, but rather end with a descriptive error message in case the config.xml file is wrong somehow. The same config.xml worked just fine in android@10.1.2.

Probably the setting AndroidWindowSplashScreenBackground is the internal cdv_splashscreen_background, but how should non-cordova-committers know? The prepare stage should not throw a null pointer -- it's that simple. It's a bug, and the documentation is not too easy to understand...

minduch commented 1 year ago

You should not install cordova-plugin-spashscreen with Cordova-Android 11, in fact cordova-plugin-spashscreen@6.0.2 will not install for Cordova-Android 11. The next major release of cordova-plugin-spashscreen will actually delete all of the source code for Android. Also the preference only controlled the cordova-plugin-spashscreen's SplashScreen.

Is there a rough "release date" for this new plugin?

???

breautek commented 1 year ago

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.

1.

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.

2.

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

TiBz0u commented 1 year ago

Hi @minduch, the accent color comes from the cordova-plugin-firebasex into the script folder See here.

We are currently upgrading to this new android version too with FirebaseX. If we encounter any similar problem, we will inform you.

Kr.

jtmuti commented 1 year ago

I use Ionic/Angular framework and "cordova prepare android" is giving the same errors (cordova-android 11.0.0 ) that minduch has. I have tried next workarounds for cordova-plugin-spashscreen: different versions, remove and set none. I need stay in android SDK 31/cordova-android 10.1.2 until fix idea or update.

TiBz0u commented 1 year ago

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.

scyclops commented 1 year ago

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

erisu commented 1 year ago

@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.

<resource-file src="res/values/myCustomAdaptiveIconColors.xml" target="/app/src/main/res/values/myCustomAdaptiveIconColors.xml" />

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 exisiting colors.xml instead of uploading a file, but it might be better create new xml files instead. There were some reports where even plugins overwritten the colors.xml file.

I will take a look in updating the documentation.

4lyn commented 1 year ago

Changing target directory doesn't help. It doesn't limit to this specific colors.xml file. It's all resource-file files listed in config.xml See #1553

ptorrent commented 8 months ago

Hello,

I removed the plugin cordova-splashcreen and I still have this issue. This is how looks my colors.xml :

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="background">#1A1C1D</color>
    <color name="cdv_splashscreen_background">#000000</color>
</resources>

What is the solution for this issue ?

Cannot set properties of null (setting 'text')
TypeError: Cannot set properties of null (setting 'text')
    at updateProjectSplashScreenBackgroundColor (C:\xxx\x\ui\node_modules\cordova-android\lib\prepare.js:489:68)
    at C:\xxx\x\ui\node_modules\cordova-android\lib\prepare.js:396:13
    at Array.forEach (<anonymous>)
    at updateProjectSplashScreen (C:\xxx\x\ui\node_modules\cordova-android\lib\prepare.js:387:7)
    at updateProjectAccordingTo (C:\xxx\x\ui\node_modules\cordova-android\lib\prepare.js:270:5)
    at C:\xxx\x\ui\node_modules\cordova-android\lib\prepare.js:68:21
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 0)
bbynog commented 7 months ago

Hi, i was getting this bug upgrading from cordova 10 to 12. I passed by it adding <color name="cdv_splashscreen_background">#FFFFFF</color> to my res/values/colors.xml. So, my colors.xml would look like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="background">#FFFFFF</color>
    <color name="cdv_splashscreen_background">#FFFFFF</color>
</resources>
amcalgates commented 3 weeks ago

Renaming colors.xml fixed the issue for me, but I had to do it in this order:

mv colors.xml myColors.xml (also change in config.xml) cordova platform remove android cordova platform add android cordova build android --verbose