androidhtmlcordovaadaptive-icon

Error when trying to build cordova app with adaptive icons


When trying to add an adaptive icon in config.xml I get the following error when trying to build

One of the following attributes are set but missing the other for the density type: ldpi, mdpi, hdpi, xhdpi, xxhdpi, xxxhdpi. Please ensure that all require attributes are defined.

My code is:

<platform name="android">
    <resource-file src="res/icon/android/colors.xml" target="/app/src/main/res/values/colors.xml" />
    <icon background="@color/background" density="ldpi" foreground="res/icon/android/ldpi-foreground.png" />
    <icon background="@color/background" density="mdpi" foreground="res/icon/android/mdpi-foreground.png" />
    <icon background="@color/background" density="hdpi" foreground="res/icon/android/hdpi-foreground.png" />
    <icon background="@color/background" density="xhdpi" foreground="res/icon/android/xhdpi-foreground.png" />
    <icon background="@color/background" density="xxhdpi" foreground="res/icon/android/xxhdpi-foreground.png" />
    <icon background="@color/background" density="xxxhdpi" foreground="res/icon/android/xxxhdpi-foreground.png" />
</platform>

I'm using cordova-android 8.0.0


Solution

  • Pasting for reference here the answer to the same question (asked by the same dev) provided here.

    @Fmaldonado6 After some digging through the code I found that it was because I was using global cordova cordova@8.1.2, upgrading to cordova@9.0.0 via npm i -g cordova@9.0.0 fixed the problem for me. This is because even though we upgraded to cordova-android@8.0.0 in our project this library depends on information passed to it from the globally installed cordova library which it gets from cordova-common@3.1.0 whereas cordova@8.1.2 has cordova-common@2.2.5 which does not pass along foreground and background props