Solvedcordova 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
46 Answers

✔️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.

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

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

Related Issues:

92
cordova android Build errors about drawable since upgrading to v8.0.0
Hello all ! This error also appears when I do release build after upgrading to cordva-android@8.0.0 ...
63
cordova android Support new Android App Bundle package format
@jfoclpf I got it working on circle ci The steps are: 4 - Upload app.aab to google play. ...
23
cordova android Back button event on full screen video closes application
add this in MainActivity.java it works. Bug Report Problem As the title suggests attempting to exit ...
17
cordova android Requirements check failed for JDK 8 ('1.8.*')! Detected version: null
Master currently has https://github.com/apache/cordova-android/blob/master/bin/templates/cordova/lib...
12
cordova android java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider
They have updated the AdMob SDK you have to add your appID in the AndroidManifest <application> ...
750
react native keychain SDK Build Tools revision (23.0.1) is too low for project :react-native-keychain.
Ok I found a solution to this For people facing the same problem in the future Hey there ...
748
material components android Manifest merger failed : Attribute application@appComponentFactory
I had similar problem We're transitioning from github issues to a public buganizer component Rather ...
746
expo Error: fsevents unavailable (this watcher can only be used on Darwin)
Possible solution: I had installed watchman via npm install -g watchman but apparently this installs...
459
flutter Multiple commands produce '/build/ios/Debug-iphonesimulator/Runner.app/Frameworks/Flutter.framework
I was able to fix it by opening the Runner workspace project in Xcode 10 Then navigate to File ...
449
flutter App Store iOS submission fails: The bundle Runner.app/Frameworks/App.framework does not support the minimum OS Version specified in the Info.plist
After doing a flutter clean changing MinimumOSVersion (inside /ios/Flutter/AppframeworkInfo.plist) t...
418
flutter 'com.android.support:appcompat-v7' has different version for the compile (26.1.0) and runtime (27.0.1) classpath
is like this i receive an error when i run flutter run My gradle.build file is: flutter doctor: ...
409
flutter Why does my text not wrap?
You have to wrap Column in a flexible Without flexible the column's width is not constrained to the ...
383
flutter Unexpected top padding in ListView put inside scaffold with no appBar
Yeah this is intentional If you put a widget before the ListView you should wrap the ListView with a...
315
flutter Missing xcode dependency: Python module "six"
try python2.x -m pip install six by @humblerookie's suggest or brew reinstall python@2 pip install s...
306
expo exp build:android fails
This works exp start Cancel ctrl c then do exp build:android. Running exp build:android errors fails...
285
flutter flutter messaging: set the notification icon
Hey guys I fought with this for the better part of a day For some strange reason there are no tutori...
281
flutter Issue with cloud_firestore - Cannot fit requested classes in a single dex file.
As a workaround you can try enabling mutlidex for Android App by following Enable multidex for apps ...
265
flutter D8: Program type already present: io.flutter.BuildConfig
@smrucv I received the same error but after flutter clean and flutter packages get everything works ...
250
238
flutter Introduction of characters package causes crash on flutter run for preexisting Flutter applications
In my case I resolved the issue with flutter clean After e0ed12c I get this error when building: @ju...
222
nativescript cli TNS doctor doesn't recognize Xcode (High Sierra)
HI @philipfeldmann Can yhou please run xcodebuild -version and paste the output? May be Xcode is ins...
221
flutter Making Network http error SocketException: Failed host lookup
@hoc081098 Double-check / make sure you have <uses-permission android:name=android.permission.INTERN...
216
flutter Support inlining Android/iOS views
iOS view embedding support has landed on master This is still just a preview There are multiple open...
207
flutter ✗ Android license status unknown.
Hi everyone Steps to Reproduce Please tell us what you were doing and what went wrong If you are run...
195
react native mapbox gl No static method toHumanReadableAscii
here is workaround: build.gradle got the following error on runtime: java.lang.NoSuchMethodError: No...
185
flutter idevice_id cannot run on catalina
When you're developing on Catalina Steps to Reproduce Run flutter doctor on macOS Catalina I get the...
181
flutter type 'List<dynamic>' is not a subtype of type 'List<String>'
The problem is your fromMap constructor is reading from a Map<String dynamic> ...
178
flutter TextField is hidden by keyboard inside of a Modal Bottom Sheet
This may not work for all situations but I have a modalBottomSheet that contains only a TextField ...
173
retrofit Kotlin & @Body
You can still use Map just suppress its wildcardness with @JvmSuppressWildcards ...
169
NativeBase Needs to tap twice to fire onPress function when keyboard is open
@bm-software Use keyboardShouldPersistTaps={'handled'} and will works fine. react-native ...
162
react native firebase 🔥(Android) Program type already present: io.invertase.firebase.BuildConfig
I think I found my ultimate error here In my package.json file I had at some point earlier ...
160
flutter Dismissing keyboard programatically
This is a better way as it also clears the focus: FocusScope.of(context).requestFocus(new FocusNode(...
157
flutter How to solve: Android license status unknown and also Android sdkmanager tool not found? Tried everything(as i think)
The answer is here Uncheck Hide Obsolete Packages and you'll see Android SDK Tools (Obsolete) 26.1.1...
156
flutter MissingPluginException: No implementation found for method
@mravn-google Yeah turned out I had to quit the flutter run process and start it up again Just a ful...
156
flutter firebase_auth: ^0.8.0+1 crashes on Android
Here i put this in file: android/gradle.properties: and changed targetSdkVersion to 28 and it worked...
156
react native modal The statusbar turns white when the modal is open (only on certain devices)
statusBarTranslucent property has been added to Modal of RN 0.62 I think this problem has been solve...
153
flutter Android sdkmanager tool not found (C:...\Local\Android\sdk\tools\bin\sdkmanager)
This worked for me: open Android Studio's SDK Manager go to the Android SDK tab under SDK Tools ...
149
flutter 1.22.2 - Flutter plugin not installed; this adds Flutter specific functionality.
Hey @bhanuka96 try this line of code How do I fix this android plugin error? This error is being com...
145
cli pod install failure with glog
what helped me: sudo xcode-select --switch /Applications/Xcode.app Ask your Question I have been try...
144
create react native app issue running on ubuntu 16.04 (watchman)
I got it working by running: OS Info: Run: Output: ...
139
flutter [ios][release] GeneratedPluginRegistrant.m Module not found
I may have found the answer from this comment: #21989 (comment) Seems like by opening up the project...
137
flutter [App.framework] Linked and embedded framework 'App.framework' was built for iOS/iOS Simulator
Does rm -rf ios/Flutter/App.framework get you unstuck? SOLUTION @jmagman has written an article on h...
137
Xposed Let's port Xposed to N
Surprisingly by porting M changes to N everything works well From my experience I can tell you that ...
134
flutter Bad state: Future already completed
I had the same issue.. The problem was the same that @soaresgabriel said but I was not navigating di...
131
create react native app AwesomeProject@0.1.0 start: react-native-scripts start- ERR! Exit status 1
As suggested at the error message installing watchman solved this error for me (OSX 10.9.5) ...
129
flutter Execution failed for task ':app:compileFlutterBuildDebug' Issue
Hi @Ramihtet your logs show a different flutter version; could you please run flutter channel stable...
126
capacitor FileReader API not firing
You can try this. Description of the problem: In my project I'm trying to read and convert a Blob do...