Search code examples
androidcordova

Cordova icon background color no build


I'm following the documentation on about to add a background color to my icon.

I created colors.xml with content

 <?xml version="1.0" encoding="utf-8"?>
 <resources>
     <color name="background">#742A84</color>
 </resources> 

And saved it in res/values/colors.xml, then added to config

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

And finally set the color for each icon, such as

 <icon density="ldpi" background="@color/background" foreground="res/icons/android/icon-36.png" />

But then when I do cordova build android, I get

TypeError [ERR_INVALID_ARG_TYPE]: The "code" argument must be of type number. Received type string ('ENOENT')
at process.set [as exitCode] (node:internal/bootstrap/node:123:9)
at C:\Users\Eric\AppData\Roaming\npm\node_modules\cordova\bin\cordova:32:22
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

I even tried cordova platform rm android then cordova platform add android, and then I get

 One of the following attributes are set but missing the other for the density type: ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi.

Removing background="@color/background" for each icon and removing

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

then the app builds. I checked the app/src/main/res/values/ and colors.xml is missing.

What am I doing wrong? Or is this another half baked feature of Cordova?


Solution

  • I will answer my own question with my own work around.

    Since I use the same color as the splashscreen, I bypassed the step to add the resource file and piggy back onto the splash screen color.

        <icon density="ldpi" background="@color/cdv_splashscreen_background" foreground="res/icons/android/icon-36.png" />
        <icon density="mdpi" background="@color/cdv_splashscreen_background" foreground="res/icons/android/icon-48.png" />
        <icon density="hdpi" background="@color/cdv_splashscreen_background" foreground="res/icons/android/icon-72.png" />
        <icon density="xhdpi" background="@color/cdv_splashscreen_background" foreground="res/icons/android/icon-96.png" />
        <icon density="xxhdpi" background="@color/cdv_splashscreen_background" foreground="res/icons/android/icon-144.png" />
        <icon density="xxxhdpi" background="@color/cdv_splashscreen_background" foreground="res/icons/android/icon-192.png" />