Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build errors about drawable since upgrading to v8.0.0 #689

Closed
3 tasks done
BorntraegerMarc opened this issue Mar 13, 2019 · 53 comments
Closed
3 tasks done

Build errors about drawable since upgrading to v8.0.0 #689

BorntraegerMarc opened this issue Mar 13, 2019 · 53 comments

Comments

@BorntraegerMarc
Copy link

BorntraegerMarc commented Mar 13, 2019

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
@BorntraegerMarc
Copy link
Author

It only happens with a production "release" build.

@dpogue
Copy link
Member

dpogue commented Mar 13, 2019

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?

@BorntraegerMarc
Copy link
Author

@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.

@apiaget
Copy link

apiaget commented Mar 18, 2019

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

@piotr-cz
Copy link

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

@BorntraegerMarc
Copy link
Author

True. Adding additionally the density without port or land does get rid of the error. Wondering what other orientations as "default" there is except from portrait and landscape

@BorntraegerMarc
Copy link
Author

OK so apparently there are a few more: https://developer.android.com/guide/topics/manifest/activity-element.html#screen

@marckassay
Copy link

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

@BorntraegerMarc
Copy link
Author

BorntraegerMarc commented Apr 1, 2019

@marckassay thanks a lot. Could you elaborate how the splash screen should look different from "default" mode to portrait mode?

And what exactly this https://gist.github.com/marckassay/913c06fac2a64a25ae9115435f8195d3/revisions?diff=unified#diff-1c17390bf45f1534c828cbeea42bb0deR7 "background / foreground" is

@marckassay
Copy link

marckassay commented Apr 6, 2019

@BorntraegerMarc my intention of that gist diff was just to highlight what @apiaget modified, to have the error disappear, which is seen in this illustration:
image

The "background / foreground" that you're referring to applies to app icons. I don't think that's relevant to the issue you reported.

Fyi, an alternative to using 'cordova-plugin-splashscreen' can be cordova-plugin-lottie-splashscreen which may be an interest to you. If you're unfamiliar with this plugin, it uses Lottie.

Lottie is a library for Android, iOS, Web, and Windows that parses Adobe After Effects animations exported as json with Bodymovin and renders them natively on mobile and on the web!

I attempted to implemented this as a replacement to 'cordova-plugin-splashscreen' but was unable to find any available animations fitting to my needs. Manually modifying the json is difficult since it's hardly readable and installing Adobe After Effects wasn't something I was going to do.

@piotr-cz
Copy link

piotr-cz commented Apr 8, 2019

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

@marckassay
Copy link

@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

@technologiespro
Copy link

technologiespro commented May 25, 2019

package.json:

cordova plugin add cordova-plugin-splashscreen

npm install

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

@ioclaudio
Copy link

I've solved creating a new directory and copying the icon as described here:
https://github.com/oliviercherrier/mauron85-background-geolocation-example-ionic2

@pmcgeebcit
Copy link

The adjustment to config.xml made by apiaget fixed it for me.Thank you for the input everyone.

@KasunGamage
Copy link

HI , i got this.
error

this is my ionic info..
ionic info

@qliqdev
Copy link

qliqdev commented Jul 3, 2019

@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:

Any solution found?

@bryplano
Copy link

bryplano commented Jul 3, 2019

Does this error occur if you run ionic cordova resources with the cordova-res library installed and then rebuild (might need to clear your platform and rebuild Android entirely)? This should be the new default as of Ionic CLI 5.X (install the latest Ionic CLI & cordova-res just to be safe) - I've never seen this error myself...

@KasunGamage - your AAPT error isn't the same one from above. Try this Github issue: arnesson/cordova-plugin-firebase#1081

@cgomezluengo
Copy link

I have the same problem I have not found anything yet, could you solve it?

@lawrencegrey
Copy link

what does this dO?

@lawrencegrey
Copy link

HI , i got this.
error

this is my ionic info..
ionic info

reduce the file size.

@nachocruel
Copy link

nachocruel commented Jul 25, 2019

To solve this error I create a diretory 'drawable' na pasta 'platforms\android\app\src\main\res' After that I copied the file screen.png and ic_launcher.png to the folder 'drawable.
Obs. the *.png files were the files used to with the comand 'ionic cordova resorses'. I just remane them with the especified name screen and ic_launcher.

@marcalbet
Copy link

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.

@toshihidetagami
Copy link

@apiaget's answer is correct. You should provide default resources.
From Android documentation (I recommend you read through the page)

Likewise, if you provide different layout resources based on the screen orientation, you should pick one orientation as your default. For example, instead of providing layout resources in layout-land/ for landscape and layout-port/ for portrait, leave one as the default, such as layout/ for landscape and layout-port/ for portrait.

I also wrote more explanation and made a pull request to fix the docs.

apache/cordova-plugin-splashscreen#228

@sts-ryan-holton
Copy link

@apiaget I've added:

<platform name="android">
        <preference name="SplashMaintainAspectRatio" value="true" />
        <icon density="ldpi" height="36" src="res/icon/android/icon-36-ldpi.png" width="36" />
        <icon density="mdpi" height="48" src="res/icon/android/icon-48-mdpi.png" width="48" />
        <icon density="hdpi" height="72" src="res/icon/android/icon-72-hdpi.png" width="72" />
        <icon density="xhdpi" height="96" src="res/icon/android/icon-96-xhdpi.png" width="96" />
        <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 src="res/splash/android/Default@2x~universal~anyany.png" />
        <allow-intent href="market:*" />
        <custom-config-file parent="/*" target="AndroidManifest.xml">
            <uses-permission android:name="android.permission.INTERNET" />
            <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
            <uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
        </custom-config-file>
    </platform>

with little luck, this doesn't seem to work

@Colombo97
Copy link

Why my image paths is different from @apiaget ??
Ex.:
<splash density="land-ldpi" src="resources\android\splash\drawable-land-ldpi-screen.png" /> <splash density="land-mdpi" src="resources\android\splash\drawable-land-mdpi-screen.png" /> <splash density="land-hdpi" src="resources\android\splash\drawable-land-hdpi-screen.png" /> <splash density="land-xhdpi" src="resources\android\splash\drawable-land-xhdpi-screen.png" /> <splash density="land-xxhdpi" src="resources\android\splash\drawable-land-xxhdpi-screen.png" /> <splash density="land-xxxhdpi" src="resources\android\splash\drawable-land-xxxhdpi-screen.png" />

gammelby added a commit to nabto/ionic-starter-nabto-video that referenced this issue Aug 30, 2019
@indraraj26
Copy link

Yes i had to update android studio along with gradle 3.5 and distributionUrl to 5.4.1-all. This is all happening due to splashscreen file size if you are having splash.png less than 100kb then it works great even with current gradle 3.3.0 otherwise it will give above error.

@bcolflesh
Copy link

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.

Thanks ppetree, this fixed it for me as well.

@bcolflesh
Copy link

In addition to removing "port-" from the portrait splashes, I had another app with large 32-bit png splashes that generated the same error, had to drop them all to 8-bit, so there is some size issue as well for the --release build as noted above.

@mikeddol
Copy link

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.

This seems to have worked for me 🤔

@ppetree
Copy link

ppetree commented Apr 26, 2020

All that does is hide the error messages, it doesn't actually "solve" the problem.

@mikeddol
Copy link

All that does is hide the error messages, it doesn't actually "solve" the problem.

Oh. So which is the right solution?

@ppetree
Copy link

ppetree commented May 2, 2020

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.

@Friday182
Copy link

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

This works for me, thanks

distante added a commit to distante/cordova-plugin-splashscreen that referenced this issue Aug 14, 2020
(Note this is an almos 1 to 1 copy of apache#228 by @toshihidetagami

### Platforms affected
Only docs
 
### Motivation and Context
Current documentation lacks the default resources for Android.
On Android, you can provide alternative resources for specific device configuration, like current docs provide alternative resources for portrait and landscape orientation. But error will be thrown if a device configuration does not match any specific alternative resources, so you should provide a default (In this case, without port- or land- ) as a fallback.
This change fixes the error reported in apache#185 and [apache/cordova-android#689](apache/cordova-android#689).
 
### Description
[Although orientation is only portrait and landscape as of now](https://developer.android.com/guide/topics/resources/providing-resources#OrientationQualifier), providing default would prevent [MissingDefaultResource lint check error](http://tools.android.com/tips/lint-checks) and considered as [good practice for Android resources configuration](https://developer.android.com/guide/topics/resources/providing-resources#Compatibility).
 
> Likewise, if you provide different layout resources based on the screen orientation, you should pick one orientation as your default. For example, instead of providing layout resources in layout-land/ for landscape and layout-port/ for portrait, leave one as the default, such as layout/ for landscape and layout-port/ for portrait.
 
Note:
You don’t have to provide a default for screen density. [The system use whichever resources are the best match](https://developer.android.com/guide/topics/resources/providing-resources#DensityQualifier).

### Testing
### Checklist
* [ ]  I've run the tests to see all new and existing tests pass
* [ ]  I added automated test coverage as appropriate for this change
* [ ]  Commit is prefixed with `(platform)` if this change only applies to one platform (e.g. `(android)`)
* [x]  If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct [keyword to close issues using keywords](https://help.github.com/articles/closing-issues-using-keywords/))
* [x]  I've updated the documentation if necessary
@jfoclpf
Copy link

jfoclpf commented Aug 24, 2020

Solution from @apiaget worked, I don't understand though why should I have the tag <splash in my config.xml since I don't have the plugin cordova-plugin-splashscreen installed

@infacto
Copy link

infacto commented Aug 31, 2020

The resources (icon, splash) should be added automatically to the config.xml when adding the android platform. That worked some time ago, right? Maybe it does not work since the platform is stored in package.json? Anyway, the config.xml should contain the platform tag with all the required settings incl. icons and splashes. Automatically.

@jfoclpf
Copy link

jfoclpf commented Aug 31, 2020

@infacto
As you can see on the respective documentation here, that is just applicable when you have the plugin installed.

@infacto
Copy link

infacto commented Sep 1, 2020

And the icons can be set by following this docs. I just expected that this configuration is added automatically on adding the Android platform and / or plugin installation. (The standard icons). But ok, you have to add this manually. I think my memories of automatically set resources are from Ionic. I thought it was Cordova. Sorry. (Not sure. But anyway... an predefined config is not the worst idea. e.g. changing the Icons is an essential configuration.)

@infacto
Copy link

infacto commented Sep 23, 2020

Confirmed: Adding the density without "land-" or "port-" fixes the issue. But what's the correct sizes? Is the default density (without prefix) for portait (port)? So I can use the same images or better, remove the density with prefix "port-"?

<splash density="ldpi" src="resources/android/splash/drawable-port-ldpi-screen.png"/>
<splash density="mdpi" src="resources/android/splash/drawable-port-mdpi-screen.png"/>
<splash density="hdpi" src="resources/android/splash/drawable-port-hdpi-screen.png"/>
<splash density="xhdpi" src="resources/android/splash/drawable-port-xhdpi-screen.png"/>
<splash density="xxhdpi" src="resources/android/splash/drawable-port-xxhdpi-screen.png"/>
<splash density="xxxhdpi" src="resources/android/splash/drawable-port-xxxhdpi-screen.png"/>

<splash density="land-ldpi" src="resources/android/splash/drawable-land-ldpi-screen.png"/>
<splash density="land-mdpi" src="resources/android/splash/drawable-land-mdpi-screen.png"/>
<splash density="land-hdpi" src="resources/android/splash/drawable-land-hdpi-screen.png"/>
<splash density="land-xhdpi" src="resources/android/splash/drawable-land-xhdpi-screen.png"/>
<splash density="land-xxhdpi" src="resources/android/splash/drawable-land-xxhdpi-screen.png"/>
<splash density="land-xxxhdpi" src="resources/android/splash/drawable-land-xxxhdpi-screen.png"/>

<!-- This can be removed: -->
<splash density="port-ldpi" src="resources/android/splash/drawable-port-ldpi-screen.png"/>
<splash density="port-mdpi" src="resources/android/splash/drawable-port-mdpi-screen.png"/>
<splash density="port-hdpi" src="resources/android/splash/drawable-port-hdpi-screen.png"/>
<splash density="port-xhdpi" src="resources/android/splash/drawable-port-xhdpi-screen.png"/>
<splash density="port-xxhdpi" src="resources/android/splash/drawable-port-xxhdpi-screen.png"/>
<splash density="port-xxxhdpi" src="resources/android/splash/drawable-port-xxxhdpi-screen.png"/>

Is this correct? Currently I have all three kinds.

UPDATE 1:
In the error log, there are 12 errors for missing "port-" and "land-". But if I add the density without prefix, the errors are gone. What does this mean? Because I use the port-size for it. I expect squared images. Idk. In this case, only declare the density without prefix. What is the MissingDefaultResource resolution? 🤔

UPDATE 2:
Ok, I found a related issue in Ionic repo. ionic-team/capacitor-assets#46
This guy uses the land-one. But I'm not sure if the app supports both orientations. But anyway, I use the landscape now for default. But I don't like the missing knowledge.

For the sake of completeness. This was my initial error without the default density:


> Task :app:lintVitalRelease
C:\projects\test-app\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]
C:\projects\test-app\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]
C:\projects\test-app\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]
C:\projects\test-app\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]
C:\projects\test-app\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]
C:\projects\test-app\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]
C:\projects\test-app\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]
C:\projects\test-app\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]
C:\projects\test-app\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]
C:\projects\test-app\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]
C:\projects\test-app\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]
C:\projects\test-app\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

I would be very grateful for any clarification. 🙏

@tadeukaiba
Copy link

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

Adding these plugins removed any build error for me.

@coloz
Copy link

coloz commented Nov 18, 2020

the same problem,cordova-android 8.1.0

`* What went wrong:
Execution failed for task ':app:mergeReleaseResources'.

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.`

@breautek
Copy link
Contributor

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.

@chill117
Copy link

The cordova splash plugin is not required to fix the "MissingDefaultResource" errors. You need to add something like the following to your config.xml file to define the defaults/fallbacks:

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

See cordova docs for more details.

NoelLH added a commit to webful-ltd/passwordmaker that referenced this issue Mar 27, 2021
raphinesse added a commit that referenced this issue May 6, 2021
Currently, we copy default splash screens to the platform folder during platform creation, but then we do not delete them when the user uses no splash screens at all. This causes #1226 and what is described in #689.

The new implementation does not return early when updating splashes and none are defined. Instead, we let the cleanup map we create initially take care of deleting all unused splash screens. This also deletes the default splashes during the first prepare after platform creation.

Fixes #1226
@ebmbook
Copy link

ebmbook commented Jun 22, 2021

The best solution is to add all your density files under www folder and point to them.
For example:
`




    <splash density="land-ldpi" src="www/assets/icons/density/land-ldpi.png"/>
    <splash density="land-mdpi" src="www/assets/icons/density/land-mdpi.png"/>
    <splash density="land-hdpi" src="www/assets/icons/density/land-hdpi.png"/>
    <splash density="land-xhdpi" src="www/assets/icons/density/land-xhdpi.png"/>
    <splash density="land-xxhdpi" src="www/assets/icons/density/land-xxhdpi.png"/>
    <splash density="land-xxxhdpi" src="www/assets/icons/density/land-xxxhdpi.png"/>

`

wedgberto pushed a commit to wedgberto/cordova-android that referenced this issue May 17, 2022
Currently, we copy default splash screens to the platform folder during platform creation, but then we do not delete them when the user uses no splash screens at all. This causes apache#1226 and what is described in apache#689.

The new implementation does not return early when updating splashes and none are defined. Instead, we let the cleanup map we create initially take care of deleting all unused splash screens. This also deletes the default splashes during the first prepare after platform creation.

Fixes apache#1226
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests