Open minduch opened 2 years ago
How to use the latest 11.0.1-dev (2)
(or later) version(s) from github in my builds?
cordova platform add android@10.1.2
(today working, 11.0.0 doesn't work)<engine name="android" spec="10.1.2"/>
Thanks in advance.
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.
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...
Is there a possible work-around to set some variable or parameter in config.xml (e.g. cdv_splashscreen_backup
)?
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.
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?
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.
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.
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:
cordova create TestApp
cd TestApp
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 accent
and cdv_splashscreen_background
._
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.
Is there a rough "release date" for this new plugin?
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.
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.
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...
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 thecordova-plugin-spashscreen
's SplashScreen.Is there a rough "release date" for this new plugin?
???
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
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.
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.
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.
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.
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
@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.
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
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)
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>
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
Worked here. Documentation should be updated. Thanks!
Though, on build, it does say:
Conflict found, edit-config changes from config.xml will overwrite plugin.xml changes
Ran into this problem too. Renaming colors.xml
resource-file like @amcalgates suggests did the trick.
Bug Report
Using Cordova 11 and Android 11.0.0, the
cordova prepare android --debug
command fails with: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:
Information
The config.xml file:
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
:If I edit the source code to include the following line before line 484:
The prepare command works a little bit longer but fails as show below, and I don't know the side-effects.
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
Checklist