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

Lack of the default/fallback resources in config.xml for Android triggers MissingDefaultResource issue #46

Closed
ryaa opened this issue Sep 4, 2019 · 6 comments

Comments

@ryaa
Copy link

ryaa commented Sep 4, 2019

When generating images for Android the cordova-res tool also registers the generated images in config.xml however it registers them for portrait and landscape orientation only. When creating a production build (using ionic cordova build android --release --prod) for android, android lint checks errors will be thrown because no defaults (In this case, without port- or land- ) as a fallback is provided. The errors are as below

/Users/alexryltsov/Git/BOSS811/master/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/alexryltsov/Git/BOSS811/master/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.)

Not sure if this tool should add these default/fallback or provide details in README how to fix these errors. Right now, the user gets the errors during the build after images are generated/registered in config.xml

To fix the errors I manually added the below

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

Please also see discussion here apache/cordova-plugin-splashscreen#228 and apache/cordova-android#689 and apache/cordova-plugin-splashscreen#185

@imhoffd imhoffd changed the title Lacks of the default/fallback resources in config.xml for Android triggers errors when building production build for Android Lack of the default/fallback resources in config.xml for Android triggers MissingDefaultResource issue Sep 5, 2019
@imhoffd
Copy link
Contributor

imhoffd commented Sep 5, 2019

Thanks for opening an issue for this! For stuff like this we're dependent on Cordova. We don't want to generate undocumented config that may work today that Cordova then changes later. It looks like neither the splashscreen plugin or cordova-android maintainers have an official response yet.

I'm subscribed to those two issues and the PR and will wait to see what happens.

@pieterjandebruyne
Copy link

bump same issue,

I also have a white screen when I build my app with --release flag..
when I run:
ionic cordova run android --livereload --consolelogs --release
this shows me the above error then goes on to install/start app

[native-run] Selected hardware device 008aff0212c24a6e
[native-run] Forwarded device port 8102 to host port 8102
[native-run] Forwarded device port 53703 to host port 53703
[native-run] Installing platforms/android/app/build/outputs/apk/release/app-release-unsigned.apk...
[native-run] Starting application activity be.thecraft.powerflowers/be.thecraft.powerflowers.MainActivity...
[native-run] Run Successful

But nothing to see on the phone..
If I build and install it the app just displays a white screen (same for ios)
If I do not build with the release tag it runs smooth..

Can this be because of these errors?

@JMooreo
Copy link

JMooreo commented Nov 15, 2019

@pieter-janDB I had the same issue. First, to get rid of the errors, see the solution given by @ryaa. Then, to fix the white screen, here is the solution that worked for me:
npm i cordova-plugin-ionic-webview@latest

@vdias38
Copy link

vdias38 commented Oct 2, 2020

These errors are not raised if we build an .aab package, instead of .apk.

@mlynch
Copy link
Contributor

mlynch commented Nov 1, 2021

Looks like a Cordova specific issue. As we're dropping Cordova support in 1.0 I am going to close unless this also impacts Capacitor. Thanks for the issue.

@mlynch mlynch closed this as completed Nov 1, 2021
@cg-roling
Copy link

cg-roling commented Sep 29, 2022

I am seeing this same error in my Capacitor project (which was upgraded from Cordova).

npx capacitor-assets generate --android creates splash screen images (see list below), but lint fails because there is no default resource.

Seems like we need either android/app/src/main/res/drawable/splash.png -or- android/app/src/main/res/drawable-somedpi/splash.png (without the "-land" or "-port" modifier) to make the lint task happy.

Possibly, rather than specifying -port and -land, only -land could be specified, and the -land folders could become the default/fallback?

Unless there's another way around this, or I have something wonky because it's an upgraded Cordova app maybe?

android/app/src/main/res/drawable-port-xxxhdpi/splash.png
android/app/src/main/res/drawable-land-xhdpi/splash.png
android/app/src/main/res/drawable-port-ldpi/splash.png
android/app/src/main/res/drawable-port-hdpi/splash.png
android/app/src/main/res/drawable-port-mdpi/splash.png
android/app/src/main/res/drawable-land-mdpi/splash.png
android/app/src/main/res/drawable-land-hdpi/splash.png
android/app/src/main/res/drawable-land-ldpi/splash.png
android/app/src/main/res/drawable-land-xxhdpi/splash.png
android/app/src/main/res/drawable-port-xxhdpi/splash.png
android/app/src/main/res/drawable-port-xhdpi/splash.png
android/app/src/main/res/drawable-land-xxxhdpi/splash.png

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

7 participants