运行Flutter App时遇Android resource linking failed:mipmap资源缺失求助
错误详情
FAILURE: 构建失败并抛出异常。
- 出错原因:
任务 ':app:processDebugResources' 执行失败。执行 com.android.build.Gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction 时发生失败
Android resource linking failed
ERROR:C:\AndroidStudioProjects\flutter_app\i_am_rich\build\app\intermediates\packaged_manifests\debug\AndroidManifest.xml:17: AAPT: error: 未找到资源 mipmap/ic_launcher(即 com.example.i_am_rich:mipmap/ic_launcher)。
解决方案
确认启动图标资源存在
检查android/app/src/main/res/目录下的mipmap-hdpi、mipmap-mdpi、mipmap-xhdpi等分辨率文件夹,确保每个文件夹中都有ic_launcher.png文件。如果缺失,补充对应分辨率的图标;若已配置flutter_launcher_icons插件,在终端执行:flutter pub run flutter_launcher_icons:main检查Manifest文件引用正确性
打开android/app/src/main/AndroidManifest.xml,找到<application>标签内的android:icon="@mipmap/ic_launcher",确认资源名称与实际文件完全一致,无拼写错误。清理并重建项目
执行以下命令清理缓存并重新构建:flutter clean flutter pub get flutter run或在Android Studio中操作:
Build > Clean Project→Build > Rebuild Project验证资源目录结构
确保mipmap文件夹命名符合Android规范(如mipmap-hdpi而非mipmap_hdpi),资源文件放置在对应分辨率的目录下,没有目录结构错误。
内容的提问来源于stack exchange,提问作者iiMoeness

