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

Flutter无法修改应用启动图标:ic_launcher.xml自动生成屏蔽自定义图标

解决Flutter Android端启动图标无法修改的问题

1. 排查Flutter自动图标生成插件

如果你的项目里配置了flutter_launcher_icons插件,它会自动生成并覆盖Android端的图标文件,导致手动修改失效:

  • 打开项目根目录的pubspec.yaml,检查是否存在如下配置块:
flutter_launcher_icons:
  android: "launcher_icon"
  ios: true
  image_path: "assets/icon/icon.png"
  • 若存在,要么修改image_path为你的自定义图标路径,执行flutter pub run flutter_launcher_icons:main重新生成图标;要么直接注释/删除该插件配置,终止自动覆盖逻辑。

2. 强制锁定Manifest图标配置

  • 打开android/app/src/main/AndroidManifest.xml,找到<application>标签的android:icon属性,手动指定你的自定义图标,比如:
<application
    android:icon="@mipmap/ic_launcher_custom"
    ...>

确保android/app/src/main/res/mipmap-*各分辨率文件夹下,都存在对应文件名的自定义图标文件。

  • 删除自动重建的ic_launcher.xml后,在Android Studio中点击File > Invalidate Caches...,重启IDE,避免IDE自动恢复该文件。

3. 清理构建缓存彻底重置

执行以下命令清理Flutter和Android的构建缓存,消除旧图标残留:

flutter clean
cd android
./gradlew clean
cd ..
flutter pub get

完成后重新构建项目,验证图标是否生效。

4. 处理第三方库的Manifest合并覆盖

部分第三方Android集成库会通过Manifest合并规则覆盖你的图标配置:

  • 在Android Studio中打开AndroidManifest.xml,点击底部的Merged Manifest标签,查看最终合并后的android:icon属性来源,定位到对应的依赖库。
  • 在<application>标签中添加tools:replace="android:icon"强制替换,同时确保Manifest根标签已添加命名空间:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.your.package.name">
    
    <application
        android:icon="@mipmap/ic_launcher_custom"
        tools:replace="android:icon"
        ...>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 08:11:40