apache / cordova-android

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

Build failed with Invalid <color> for given resource value. error #1714

Open eduardojmrosa opened 6 months ago

eduardojmrosa commented 6 months ago

Hi, my project as cordova 12 with android 12 and i just update the android platform to 13, i change my jdk version to 17 and my gradle to 8.7 but when i run the cordova run android it keep send me this error

Task :app:mergeDebugResources FAILED C:\Users\eduar.gradle\caches\transforms-4\01bf680c3083cc7cc00592872a745a49\transformed\jetified-play-services-base-18.0.1\res\values\values.xml:4:0: Invalid for given resource value.

Already removed the platform, added it back. Clear the gradle cache and force npm cache clear.

breautek commented 6 months ago

values.xml is not a file that Cordova prepares. So it's likely caused by a plugin that your project has installed.

Might be easy to scan the plugins/ folder to see if anyone of your plugins references values.xml, and if they do; that plugin is most likely the culprit. If you find no references, then it could be coming from a native library being imported by that plugin. In which case I think the best way to determine which plugin is causing the problem is to setup a new project and add each plugin one at a time. Once the project breaks, then you probably found the bad plugin.

When using a hello world app project to test your plugins, Start the build with no plugins installed to rule out that a basic hello world doesn't actually reproduce your issue in your environent. Then proceed to install one plugin at a time and rebuilding after each plugin install.

Let us know what you find.

eduardojmrosa commented 6 months ago

I just find out that is the cordova plugin googlemaps givin this error. My app is purely based on this plugin. This error came out in this update. I have a project with android 12 that work pretty well with the same versions. Anything i can do to solve this?

eduardojmrosa commented 6 months ago

steps i took to find out -copy my angular project to a new folder -create new app with cordova -add android 13

breautek commented 6 months ago

I assume you mean https://github.com/mapsplugin/cordova-plugin-googlemaps/tree/master

My workplace utilises this plugin as well, unfortunately the original author no longer maintains it. If you're using the original version, the gmaps the plugin installs by default is quite dated. The plugin also doesn't have values.xml so perhaps it's coming from google maps sdk. My workplace maintains a fork but it also has proprietary code attached so it's not exactly usable as is.

I did run a dev build of cordova-android@13 against my apps awhile back (approx. a year ago...) without issue. Maybe because my apps are using a more recent version of gmaps sdk. You could try applying https://github.com/totalpave/cordova-plugin-googlemaps/commit/f74b8e49fe832e0e2fec46e82904d2b504753574 to your own fork to see if it solves your issue.

The original plugin has the ability to set the version via config.xml but it uses the same variable for multiple dependencies, and there is no 18.2.0 version for com.google.android.gms:play-services-location. The linked changeset above separates out the variables and sets the default value to the latest versions at the time of the changeset... the current android gmaps version today is still 18.2.0

breautek commented 6 months ago

For what it's worth I just updated one of my apps to use cordova-android@13 and didn't encounter build issues with google maps plugin. I also reverted those versions back down to what is in the original repo and didn't reproduce the issue either.

If you could package up and share your sample reproduction issue that reproduces your issue I can try taking a deeper look.

eduardojmrosa commented 6 months ago

Any idea how i can show it to you ? I just create an empty cordova project with cordova 12 and add the android 13, installed this plugin: https://github.com/mapsplugin/cordova-plugin-googlemaps and it gives me the above error.
Could you give me your enviroment spec ? maybe my gradle or any config file like config.xml must change to make it work.

breautek commented 6 months ago

Any idea how i can show it to you ? I just create an empty cordova project with cordova 12 and add the android 13, installed this plugin: https://github.com/mapsplugin/cordova-plugin-googlemaps and it gives me the above error. Could you give me your enviroment spec ? maybe my gradle or any config file like config.xml must change to make it work.

Any idea how i can show it to you ? I just create an empty cordova project with cordova 12 and add the android 13, installed this plugin: https://github.com/mapsplugin/cordova-plugin-googlemaps and it gives me the above error. Could you give me your enviroment spec ? maybe my gradle or any config file like config.xml must change to make it work.

I cannot explain why downgrading my version numbers didn't reproduce the issue but using the original authored plugin on a base hello world project does reproduce the issue. Likewise updating the version numbers doesn't correct it either.

This is out of scope of cordova-android but I'll spend a few minutes digging to see if I can find an explanation.

breautek commented 6 months ago

K so my original statement is wrong, it is a bug with cordova-android introduced by https://github.com/apache/cordova-android/pull/1700

It looks like the intent is to set the default background color to white (#FFFFFF) but it seems like it ends up defaulting to 0 instead which is an incorrect color value.

Task :app:mergeDebugResources FAILED
C:\Users\eduar.gradle\caches\transforms-4\01bf680c3083cc7cc00592872a745a49\transformed\jetified-play-services-base-18.0.1\res\values\values.xml:4:0: Invalid for given resource value.

Definitely threw me off leading to believe the issue is elsewhere.

If you explicitly set the AndroidWindowSplashScreenBackground preference, it should work around the Invalid color issue.

Do note that the google maps plugin has several other issues and will not build without further changes. But the Invalid for given resource value issue is a bug in cordova-android@13.

Edit: I'm not entirely sure if #1700 is to blame but I don't think I encountered this in my testing in my own apps because I do have AndroidWindowSplashScreenBackground explicitly defined. #1700 just adds in more preferences to make Android match more closely with the iOS platform.

Edit 2: I observe the android platform being set up properly but it turns to 0 if the build errors for some reason. e.g. building with gmaps without supplying an API key causes a build error and when that occurs the value in colors.xml becomes 0, causing the next build to error on an invalid color.

eduardojmrosa commented 6 months ago

So even fixing this problem i may found problems with the android13 version using the maps plugin ?

eduardojmrosa commented 6 months ago

Ok, i just tested here, find some errors with permissions and with the transpiling the plugin googlempas to fit in android13 standards, so now the googlemaps plugin will need to be upgraded to fit in the android13 version. Thanks for your help! If you find any repo or method to adapt the current googlemaps plugin to work in this android13 version share with me please :D

eduardojmrosa commented 6 months ago

Update: This fork https://github.com/TSFArg/cordova-plugin-googlemaps/tree/master have a version that work pretty well with the android 13 version. It only work setting the "AndroidWindowSplashScreenBackground" in the config.xml

Edit: The right link to the maps plugin is this one: https://github.com/marutifh/cordova-plugin-fcm-with-dependecy-updated/tree/master

GitToTheHub commented 5 months ago

@eduardojmrosa Thanks for sharing the fork for the fixed google maps plugin. The link points to https://github.com/apache/cordova-android/issues/fork and not https://github.com/TSFArg/cordova-plugin-googlemaps/tree/master. Maybe you can edit this :)

Do you have already good experiences with this fork?

eduardojmrosa commented 5 months ago

Greetings, i have to update this thread. This isnt the version of the mapsplugins that works well in the New Android version. Ill edit soon.

rickysut commented 5 months ago

package android.support.annotation does not exist error in my side

sunco007 commented 4 months ago

I had this problem and searched in various places until I found what I was looking for.

I created a new project and added the plugins one by one, testing each time. After installing each plugin and testing, there were no errors. So, I copied the config.xml file from the project where I was having issues, and when I tried to compile, it gave me an error.

I deleted groups of lines until I found my problem. The line was the following:

<preference name="SplashScreenBackgroundColor" value="white" />

Changing "white" to "#ffffff" worked for me.

This happened only after updating to Android 13.0.0.

Just for the record I have these plugins:

cordova-plugin-app-version 0.1.14 "AppVersion" cordova-plugin-customurlscheme 5.0.2 "Custom URL scheme" cordova-plugin-deeplinks 1.1.1 "Cordova Deeplinks Plugin" cordova-plugin-device-name 1.3.5 "Device-Name" cordova-plugin-device 2.1.0 "Device" cordova-plugin-dialogs 2.0.2 "Notification" cordova-plugin-fullscreen 1.3.0 "cordova-plugin-fullscreen" cordova-plugin-in-app-youtube 1.0.0 "Cordova Plugin in app YouTube" cordova-plugin-inappbrowser 6.0.0 "InAppBrowser" cordova-plugin-nativestorage 2.3.2 "NativeStorage" cordova-plugin-safariviewcontroller 2.0.0 "SafariViewController" cordova-plugin-screen-orientation 3.0.4 "Screen Orientation" cordova-plugin-splashscreen 6.0.2 "Splashscreen" cordova-plugin-statusbar 4.0.0 "StatusBar" cordova-plugin-vibration 3.1.1 "Vibration" cordova-plugin-x-socialsharing 6.0.4 "SocialSharing" es6-promise-plugin 4.2.2 "Promise"

GitToTheHub commented 1 month ago

@breautek @eduardojmrosa If found the bug in cordova-plugin-googlemaps. The plugin sets

<preference name="BackgroundColor" value="0"/>

for the config.xml, for the deprecated Crosswalk WebView. It should be #000000, but this would also set the splash screen background color to black. I made a PR which fixes the issue: https://github.com/mapsplugin/cordova-plugin-googlemaps/pull/2941