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

Flutter 2.18.0 SDK中自定义启动页报错:无法解析drawable符号

问题排查与解决步骤

首先注意到报错信息里的文件名是launcher_background,但你提供的代码里引用的是launch_background,这是核心矛盾点,按以下步骤逐一排查:

  • 检查文件命名与引用一致性
    确认android/app/src/main/res/drawable(或对应分辨率的drawable-xxx目录)下的启动背景文件名:

    • 如果文件实际叫launcher_background.xml,把style.xml里的引用改成@drawable/launcher_background
    • 如果文件是launch_background.xml,检查项目中其他位置(比如AndroidManifest.xml、其他drawable文件)是否误写了launcher_background
  • 确认修改的是正确的配置文件
    确保你编辑的是android/app/src/main/res/values/styles.xml(或values-xxx目录下的对应样式文件),而非其他路径的同名文件

  • 清理项目缓存并重建
    执行以下命令清理缓存:

    flutter clean
    flutter pub get
    

    然后在Android Studio中执行Build -> Clean Project,再Build -> Rebuild Project,缓存问题常导致这类找不到资源的错误

  • 验证自定义启动背景文件的正确性
    如果是自己创建的launch_background.xml,确保其结构正确,示例如下:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <!-- 背景色 -->
        <item android:drawable="@color/launch_background_color" />
        <!-- 居中显示的自定义图标 -->
        <item>
            <bitmap
                android:gravity="center"
                android:src="@drawable/your_custom_launcher_icon" />
        </item>
    </layer-list>
    

    其中your_custom_launcher_icon需是已放入drawable目录的图标文件

内容的提问来源于stack exchange,提问作者UserSynergy

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 17:09:32