Fixed
Status Update
Comments
ca...@gmail.com <ca...@gmail.com> #2
Proof of concept demo on Github: https://github.com/casperbang/MissingNonLocalizedDrawableCrash
No problem compiling, lint'ing or running the app on a Danish device. Crash when running on a device set to any other locale.
No problem compiling, lint'ing or running the app on a Danish device. Crash when running on a device set to any other locale.
tn...@google.com <tn...@google.com> #3
I should probably generalize the translation detector's extra strings check, which is exactly this issue (but currently limited to strings checks).
tn...@google.com <tn...@google.com> #4
Finally got to this one. This is implemented for 3.2 canary 7 (along with a bunch of other fixes; it can now run the translation checks on the fly in the IDE; there are some quickfixes, etc.)
Here's what I get on the sample project:
> Task :app:lintDebug
/home/tnorbye/AndroidStudioProjects/bugs/MissingNonLocalizedDrawableCrash/app/src/main/res/drawable-da-xxxhdpi/sticker_ci.png: Error: The drawable "sticker_ci" in drawable-da-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.)
1 errors, 0 warnings
Thanks for the report!
Here's what I get on the sample project:
> Task :app:lintDebug
/home/tnorbye/AndroidStudioProjects/bugs/MissingNonLocalizedDrawableCrash/app/src/main/res/drawable-da-xxxhdpi/sticker_ci.png: Error: The drawable "sticker_ci" in drawable-da-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.)
1 errors, 0 warnings
Thanks for the report!
Description
When providing localized drawables (I.e. /drawable-en-xxxhdpi/img.png) if a default non-localized version is not provided, it's very common to see production error logs on the following form:
android.content.res.Resources$NotFoundException: Resource ID #0x7f02005d
at android.content.res.Resources.getValue(Resources.java:1343)
at android.content.res.Resources.getDrawable(Resources.java:819)
at android.content.res.Resources.getDrawable(Resources.java:799)
at android.content.Context.getDrawable(Context.java:403)
This can happen, if one forgets to test on a device for which a specific drawable has *not* been created for. This could and should be avoided, by having AS/Lint check for this fallback drawable. No such Lint rule can be found in the official documentation (