Solvedcordova android Build errors about drawable since upgrading to v8.0.0
✔️Accepted Answer
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
Other Answers:
It only happens with a production "release" build.
@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.
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
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:
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
Checklist