Cordova Android启动屏生成报错:无效资源目录名称求解决
Alright, let's break down what's going on here. That error you're seeing is happening because Android's resource directory naming rules don't recognize landscape or portrait as valid orientation labels — it only uses the shorthand land (for landscape) and port (for portrait).
When Cordova sets up the Android platform from your config.xml settings, it takes the density value you specified for each splash screen and uses it directly to create resource directories (like drawable-xhdpi-portrait). Since that name doesn't follow Android's rules, the build process throws that invalid directory error.
Here's how to fix it:
Update your
config.xmlsplash screen configurations
Swap out all instances of-landscapeand-portraitin thedensityattributes with-landand-portinstead. Your updated Android platform block should look like this:<platform name="android"> <splash density="hdpi-land" src="res/screen/android/screen-hdpi-landscape.png" /> <splash density="ldpi-land" src="res/screen/android/screen-ldpi-landscape.png" /> <splash density="mdpi-land" src="res/screen/android/screen-mdpi-landscape.png" /> <splash density="xhdpi-land" src="res/screen/android/screen-xhdpi-landscape.png" /> <splash density="hdpi-port" src="res/screen/android/screen-hdpi-portrait.png" /> <splash density="ldpi-port" src="res/screen/android/screen-ldpi-portrait.png" /> <splash density="mdpi-port" src="res/screen/android/screen-mdpi-portrait.png" /> <splash density="xhdpi-port" src="res/screen/android/screen-xhdpi-portrait.png" /> <!-- Keep all your other existing Android configs here --> </platform>You don't need to rename your actual splash image files — just adjust the
densityvalues in the config, and Cordova will map them correctly to the right resource directories.Clean up and rebuild the Android platform
To make sure no old, invalid directories are hanging around, it's best to refresh the Android platform:cordova platform remove android cordova platform add androidIf you don't want to remove the platform entirely, you can clean the build cache and rebuild instead:
cordova clean android cordova build android
Quick bonus tip:
If you're using a newer version of Cordova, consider using the cordova-res tool to auto-generate all your splash screens and icons. It handles all the naming and directory structure rules automatically, so you won't run into these kinds of manual configuration errors again.
内容的提问来源于stack exchange,提问作者Ryan H

