cordova-android: Build errors about drawable since upgrading to v8.0.0

Bug Report

Problem

What is expected to happen?

Building a cordova app with ionic cordova build android --prod --release does not throw errors.

What does actually happen?

I see this error in the console:

/platforms/android/app/src/main/res/drawable-land-hdpi/screen.png: Error: The drawable "screen" in drawable-land-hdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]

Information

This error was not present in v7.X

I do specify a splash screen in config.xml like so: <splash density="land-hdpi" src="resources/android/splash/drawable-land-hdpi-screen.png" />

And it gets displayed correctly (according to my tests so far)

I’m using this plugin to configure the splash screens: https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-splashscreen/

I only included 1 example of the errors I’m getting to keep the bug report small. But I get it for different screen sizes & densities.

I understand that it has something to do with android linting rules: http://tools.android.com/tips/lint-checks

But I don’t fully understand if it’s a misconfiguration in the plugin or if cordova-android needs to do something differently.

Command or Code

ionic cordova build android --prod --release

Environment, Platform, Device

On all. It happens on build time.

Version information

~/Documents/komed/komed-frontend$ ionic info

Ionic:

   ionic (Ionic CLI)  : 4.11.0 (/Users/borntsch/.nvm/versions/node/v8.13.0/lib/node_modules/ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.2.3

Cordova:

   cordova (Cordova CLI) : 8.0.0
   Cordova Platforms     : android 8.0.0, browser 5.0.4, ios 5.0.0
   Cordova Plugins       : cordova-plugin-ionic-webview 2.3.1, (and 27 other plugins)

System:

   Android SDK Tools : 26.1.1 (/Users/borntsch/Library/Android/sdk)
   ios-deploy        : 1.9.2
   ios-sim           : 7.0.0
   NodeJS            : v8.13.0 (/Users/borntsch/.nvm/versions/node/v8.13.0/bin/node)
   npm               : 6.4.1
   OS                : macOS Mojave
   Xcode             : Xcode 10.1 Build version 10B61

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 31
  • Comments: 53 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Hello all !

This error also appears when I do release build after upgrading to cordva-android@8.0.0.

I noticed that the error/warning disappear when I do the following modifications in my config.xml file:

Before (the following rises 4 errors/warning):

<platform name="android">
    <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application">
        <application android:usesCleartextTraffic="true">
        </application>
    </edit-config>
    <preference name="loadUrlTimeoutValue" value="700000" />
    <icon background="res/icons/android/ldpi-background.png" density="ldpi" foreground="res/icons/android/ldpi-foreground.png" src="res/icons/android/drawable-ldpi-icon.png" />
    <icon background="res/icons/android/mdpi-background.png" density="mdpi" foreground="res/icons/android/mdpi-foreground.png" src="res/icons/android/drawable-mdpi-icon.png" />
    <icon background="res/icons/android/hdpi-background.png" density="hdpi" foreground="res/icons/android/hdpi-foreground.png" src="res/icons/android/drawable-hdpi-icon.png" />
    <icon background="res/icons/android/xhdpi-background.png" density="xhdpi" foreground="res/icons/android/xhdpi-foreground.png" src="res/icons/android/drawable-xhdpi-icon.png" />
    <icon background="res/icons/android/xxhdpi-background.png" density="xxhdpi" foreground="res/icons/android/xxhdpi-foreground.png" src="res/icons/android/drawable-xxhdpi-icon.png" />
    <icon background="res/icons/android/xxxhdpi-background.png" density="xxxhdpi" foreground="res/icons/android/xxxhdpi-foreground.png" src="res/icons/android/drawable-xxxhdpi-icon.png" />
    <splash density="port-hdpi" src="res/screen/android/splash-port-hdpi.png" />
    <splash density="port-ldpi" src="res/screen/android/splash-port-ldpi.png" />
    <splash density="port-mdpi" src="res/screen/android/splash-port-mdpi.png" />
    <splash density="port-xhdpi" src="res/screen/android/splash-port-xhdpi.png" />
</platform>

After (the following rises no error/warning):

<platform name="android">
    <edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application">
        <application android:usesCleartextTraffic="true">
        </application>
    </edit-config>
    <preference name="loadUrlTimeoutValue" value="700000" />
    <icon background="res/icons/android/ldpi-background.png" density="ldpi" foreground="res/icons/android/ldpi-foreground.png" src="res/icons/android/drawable-ldpi-icon.png" />
    <icon background="res/icons/android/mdpi-background.png" density="mdpi" foreground="res/icons/android/mdpi-foreground.png" src="res/icons/android/drawable-mdpi-icon.png" />
    <icon background="res/icons/android/hdpi-background.png" density="hdpi" foreground="res/icons/android/hdpi-foreground.png" src="res/icons/android/drawable-hdpi-icon.png" />
    <icon background="res/icons/android/xhdpi-background.png" density="xhdpi" foreground="res/icons/android/xhdpi-foreground.png" src="res/icons/android/drawable-xhdpi-icon.png" />
    <icon background="res/icons/android/xxhdpi-background.png" density="xxhdpi" foreground="res/icons/android/xxhdpi-foreground.png" src="res/icons/android/drawable-xxhdpi-icon.png" />
    <icon background="res/icons/android/xxxhdpi-background.png" density="xxxhdpi" foreground="res/icons/android/xxxhdpi-foreground.png" src="res/icons/android/drawable-xxxhdpi-icon.png" />
    <splash density="hdpi" src="res/screen/android/splash-port-hdpi.png" />
    <splash density="port-hdpi" src="res/screen/android/splash-port-hdpi.png" />
    <splash density="ldpi" src="res/screen/android/splash-port-ldpi.png" />
    <splash density="port-ldpi" src="res/screen/android/splash-port-ldpi.png" />
    <splash density="mdpi" src="res/screen/android/splash-port-mdpi.png" />
    <splash density="port-mdpi" src="res/screen/android/splash-port-mdpi.png" />
    <splash density="xhdpi" src="res/screen/android/splash-port-xhdpi.png" />
    <splash density="port-xhdpi" src="res/screen/android/splash-port-xhdpi.png" />
</platform>

Do you think that adding the “default” densities is correct to solve this problem (hdpi, ldpi, mdpi and xhdpi in my case) or is the error caused by something else ? In fact I do not really know if I am really solving the problem or just workarounding it…

apiaget

It only happens with a production “release” build.

Here is a gist diff of @apiaget’s before and after.

@dpogue I can confirm that the build succeeds but the sub task > Task :app:lintVitalRelease seems to fail (but it doesn’t cause the full build to fail). Not sure how to explain. Here’s my output:

> Task :app:lintVitalRelease
/Users/borntsch/Documents/komed/komed-frontend/platforms/android/app/src/main/res/drawable-land-hdpi/screen.png: Error: The drawable "screen" in drawable-land-hdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
/Users/borntsch/Documents/komed/komed-frontend/platforms/android/app/src/main/res/drawable-land-ldpi/screen.png: Error: The drawable "screen" in drawable-land-ldpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
/Users/borntsch/Documents/komed/komed-frontend/platforms/android/app/src/main/res/drawable-land-mdpi/screen.png: Error: The drawable "screen" in drawable-land-mdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
/Users/borntsch/Documents/komed/komed-frontend/platforms/android/app/src/main/res/drawable-land-xhdpi/screen.png: Error: The drawable "screen" in drawable-land-xhdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
/Users/borntsch/Documents/komed/komed-frontend/platforms/android/app/src/main/res/drawable-land-xxhdpi/screen.png: Error: The drawable "screen" in drawable-land-xxhdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
/Users/borntsch/Documents/komed/komed-frontend/platforms/android/app/src/main/res/drawable-land-xxxhdpi/screen.png: Error: The drawable "screen" in drawable-land-xxxhdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
/Users/borntsch/Documents/komed/komed-frontend/platforms/android/app/src/main/res/drawable-port-hdpi/screen.png: Error: The drawable "screen" in drawable-port-hdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
/Users/borntsch/Documents/komed/komed-frontend/platforms/android/app/src/main/res/drawable-port-ldpi/screen.png: Error: The drawable "screen" in drawable-port-ldpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
/Users/borntsch/Documents/komed/komed-frontend/platforms/android/app/src/main/res/drawable-port-mdpi/screen.png: Error: The drawable "screen" in drawable-port-mdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
/Users/borntsch/Documents/komed/komed-frontend/platforms/android/app/src/main/res/drawable-port-xhdpi/screen.png: Error: The drawable "screen" in drawable-port-xhdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
/Users/borntsch/Documents/komed/komed-frontend/platforms/android/app/src/main/res/drawable-port-xxhdpi/screen.png: Error: The drawable "screen" in drawable-port-xxhdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]
/Users/borntsch/Documents/komed/komed-frontend/platforms/android/app/src/main/res/drawable-port-xxxhdpi/screen.png: Error: The drawable "screen" in drawable-port-xxxhdpi has no declaration in the base drawable folder or in a drawable-densitydpi folder; this can lead to crashes when the drawable is queried in a configuration that does not match this qualifier [MissingDefaultResource]

   Explanation for issues of type "MissingDefaultResource":
   If a resource is only defined in folders with qualifiers like -land or -en,
   and there is no default declaration in the base folder (layout or values
   etc), then the app will crash if that resource is accessed on a device
   where the device is in a configuration missing the given qualifier.

   As a special case, drawables do not have to be specified in the base
   folder; if there is a match in a density folder (such as drawable-mdpi)
   that image will be used and scaled. Note however that if you  only specify
   a drawable in a folder like drawable-en-hdpi, the app will crash in
   non-English locales.

   There may be scenarios where you have a resource, such as a -fr drawable,
   which is only referenced from some other resource with the same qualifiers
   (such as a -fr style), which itself has safe fallbacks. However, this still
   makes it possible for somebody to accidentally reference the drawable and
   crash, so it is safer to create a default dummy fallback in the base
   folder. Alternatively, you can suppress the issue by adding
   tools:ignore="MissingDefaultResource" on the element.

   (This scenario frequently happens with string translations, where you might
   delete code and the corresponding resources, but forget to delete a
   translation. There is a dedicated issue id for that scenario, with the id
   ExtraTranslation.)

12 errors, 0 warnings

> Task :app:mergeReleaseShaders
> Task :app:compileReleaseShaders
> Task :app:generateReleaseAssets
> Task :CordovaLib:mergeReleaseShaders
> Task :CordovaLib:compileReleaseShaders
> Task :CordovaLib:generateReleaseAssets
> Task :CordovaLib:packageReleaseAssets
> Task :app:mergeReleaseAssets
> Task :app:signingConfigWriterRelease
> Task :app:transformClassesWithDexBuilderForRelease
> Task :app:transformDexArchiveWithExternalLibsDexMergerForRelease
> Task :app:transformDexArchiveWithDexMergerForRelease
> Task :app:mergeReleaseJniLibFolders
> Task :CordovaLib:compileReleaseNdk NO-SOURCE
> Task :CordovaLib:mergeReleaseJniLibFolders
> Task :CordovaLib:transformNativeLibsWithMergeJniLibsForRelease
> Task :CordovaLib:transformNativeLibsWithIntermediateJniLibsForRelease
> Task :app:transformNativeLibsWithMergeJniLibsForRelease
> Task :app:processReleaseJavaRes NO-SOURCE
> Task :app:transformResourcesWithMergeJavaResForRelease
> Task :app:packageRelease
> Task :app:assembleRelease
> Task :app:cdvBuildRelease

BUILD SUCCESSFUL in 29s
43 actionable tasks: 43 executed
Built the following apk(s): 
	/Users/borntsch/Documents/komed/komed-frontend/platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk
✨  Done in 177.81s.

In the portrait images, take off the “port-” so they just have the resolution like this: port-ldpi to ldpi

Only do this on the portrait images! Report back.

Sent from my iPad, please excuse typos and autocorrects.

On Nov 26, 2019, at 10:53 PM, evazc notifications@github.com wrote:

Hi all, I tried all of the above solutions but it still didn’t work. Is there anyone like me?

I have tried to add this in the config.xml

    <splash density="land-ldpi" src="res/screen/android/screen-ldpi-landscape.png" />
    <splash density="port-ldpi" src="res/screen/android/screen-ldpi-portrait.png" />
    <splash density="land-mdpi" src="res/screen/android/screen-mdpi-landscape.png" />
    <splash density="port-mdpi" src="res/screen/android/screen-mdpi-portrait.png" />
    <splash density="land-hdpi" src="res/screen/android/screen-hdpi-landscape.png" />
    <splash density="port-hdpi" src="res/screen/android/screen-hdpi-portrait.png" />
    <splash density="land-xhdpi" src="res/screen/android/screen-xhdpi-landscape.png" />
    <splash density="port-xhdpi" src="res/screen/android/screen-xhdpi-portrait.png" />
    <splash density="land-xxhdpi" src="res/screen/android/screen-xxhdpi-landscape.png" />
    <splash density="port-xxhdpi" src="res/screen/android/screen-xxhdpi-portrait.png" />
    <splash density="land-xxxhdpi" src="res/screen/android/screen-xxxhdpi-landscape.png" />
    <splash density="port-xxxhdpi" src="res/screen/android/screen-xxxhdpi-portrait.png" />

And tried to change build.gradle like @mikepsinn .

I would appreciate any suggestions could help me.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

package.json:

cordova plugin add cordova-plugin-splashscreen

npm install

config.xml add: … <plugin name="cordova-plugin-splashscreen" spec="^5.0.2" />

FWIW, this issue still exists in 9.0.0.

The config.xml updates didn’t work for me, unfortunately, However, adding this to my project_root/build-extras.gradle resolved the issue:

allprojects {
    configurations.matching { it.name == '_internal_aapt2_binary' }.all { config ->
        config.resolutionStrategy.eachDependency { details ->
            details.useVersion("3.5.0-alpha03-5252756")
        }
    }
}

Then I added a hook like this to copy it to the build folder: https://github.com/QuantiModo/quantimodo-android-chrome-ios-web-app/blob/develop/hooks/build-extras-hook.js

I can confirm that suggestion by @apiaget makes error/ warnings go away.

I have renamed resources with density="port-*" to density="*" since there is only portrait mode in the my app

ionic cordova plugin add cordova-plugin-androidx
ionic cordova plugin add cordova-plugin-androidx-adapter

Adding these plugins removed any build error for me.

Hi all, I tried all of the above solutions but it still didn’t work. Is there anyone like me?

I have tried to add this in the config.xml

        <splash density="land-ldpi" src="res/screen/android/screen-ldpi-landscape.png" />
        <splash density="port-ldpi" src="res/screen/android/screen-ldpi-portrait.png" />
        <splash density="land-mdpi" src="res/screen/android/screen-mdpi-landscape.png" />
        <splash density="port-mdpi" src="res/screen/android/screen-mdpi-portrait.png" />
        <splash density="land-hdpi" src="res/screen/android/screen-hdpi-landscape.png" />
        <splash density="port-hdpi" src="res/screen/android/screen-hdpi-portrait.png" />
        <splash density="land-xhdpi" src="res/screen/android/screen-xhdpi-landscape.png" />
        <splash density="port-xhdpi" src="res/screen/android/screen-xhdpi-portrait.png" />
        <splash density="land-xxhdpi" src="res/screen/android/screen-xxhdpi-landscape.png" />
        <splash density="port-xxhdpi" src="res/screen/android/screen-xxhdpi-portrait.png" />
        <splash density="land-xxxhdpi" src="res/screen/android/screen-xxxhdpi-landscape.png" />
        <splash density="port-xxxhdpi" src="res/screen/android/screen-xxxhdpi-portrait.png" />

And tried to change build.gradle like @mikepsinn .

I would appreciate any suggestions could help me.

Closing this issue because it’s old and obsolete. I’ll summarise the problem and potential solutions below.

This problem can be caused by one or a mixture of:

  • Out-dated android build tools. Use the Android SDK Manager to ensure you have the required tooling installed. Also check your environment variables to ensure it’s pointed to the correct versions. [1]
  • You’re missing the default resource. This generally happens if you specify a splashscreen asset specifically for landscape or portrait, but failed to provide a fallback. See the example above.

[1] Linked reference is for cordova-android@9. cordova-android@8 is no longer google play store compliant and is not supported.

@coloz

java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.v2.Aapt2InternalException: AAPT2 aapt2-3.3.0-5013011-windows Daemon #6: Unexpected error during compile ‘E:\Git\blinker-app\platforms\android\app\src\main\res\drawable-land-xxhdpi\screen.png’, attempting to stop daemon. This should not happen under normal circumstances, please file an issue if it does.`

This is not the same problem. And it sounds like you’re running into an unhandled failure case inside AAPT, which is an android tool. So that’s where that error should be reported. Additionally you can double check and ensure you’re running the latest patch of the android build tools.

Changing the config entry seems to solve the problem. The images display properly and the warnings and errors go away. This is the workaround until either cordova is fixed OR the docs are fixed.

All that does is hide the error messages, it doesn’t actually “solve” the problem.

Same problem. Resolve by converting my PNG 32 bit color splashcreen image to PNG 24.

To solve these errors, go to:

platforms\android\app

and in your build.gradle file add this line “checkReleaseBuilds false;” inside lintOptions block like this:

lintOptions {
      checkReleaseBuilds false;
}

Hope it helps.

@piotr-cz you may be right. It seems those attributes are, as you have listed, for adaptive icons for Android devices too, where the icons can be in a various shapes. Such as these: image

And config.xml supports fallback for devices that don’t have this feature.

… src attribute must be defined when then foreground attribute is defined with a vector or color …

Where the value of src, in this example, is a png file.

It will nice to see the day when we just provide a background and foreground vector values.

ref: Cordova/Images/Adaptive Icons

foreground/ background attributes may be related to new Google Play app icon specifications - am I right, @marckassay ?

Android Developers blog: Introducing a new Google Play app and game icon specification Android Developers > Docs > Adaptive icons

I’ve seen this too, but even though it says “Error” in the message, it seems more like a warning in that it seems to produce a working build. @BorntraegerMarc can you confirm that this is not causing your build to fail?