You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Cordova Android启动屏生成报错:无效资源目录名称求解决

Fixing the "Invalid resource directory name" Error for Cordova Android Splash Screens

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:

  1. Update your config.xml splash screen configurations
    Swap out all instances of -landscape and -portrait in the density attributes with -land and -port instead. 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 density values in the config, and Cordova will map them correctly to the right resource directories.

  2. 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 android
    

    If 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:22:47