使用flutter_launcher_icons修改iOS应用图标出现Assets.car错误如何解决?
解决方案
问题根因:Assets.xcassets同时被Xcode默认编译流程和CocoaPods的资源复制脚本处理,导致重复生成Assets.car文件产生冲突,结合flutter_launcher_icons的使用场景,按以下顺序排查即可:
- 第一步:移除重复的资源引用
打开Xcode,选中左侧导航栏的Runner项目,在Targets下选择Runner,切换到Build Phases标签页:- 检查
Compile Sources和Copy Bundle Resources两个分区,删除所有重复的Assets.xcassets条目,仅保留1条根目录下的ios/Runner/Assets.xcassets - 检查
Assets.xcassets下的AppIcon子项,不要单独勾选其Target Membership,仅保持父级Assets.xcassets的勾选状态即可
- 检查
- 第二步:添加CocoaPods资源过滤规则
打开ios目录下的Podfile,在末尾添加以下代码,禁止CocoaPods处理xcassets类型资源,避免重复编译:
代码添加完成后,在ios目录下执行以下命令重新安装依赖:post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| # 排除所有xcassets资源,避免和Xcode默认编译冲突 config.build_settings['EXCLUDED_SOURCE_FILE_NAMES'] = '*.xcassets' end end endpod deintegrate rm Podfile.lock pod install - 第三步:清理缓存重新构建
回到项目根目录执行以下命令清理所有缓存后重新构建:
之后重新打开Xcode执行构建即可。flutter clean rm -rf ios/build flutter pub get - 临时兼容方案(非必要不推荐)
如果以上步骤仍未解决,可临时切换Xcode构建系统为旧版兼容模式:打开Xcode -> File -> Workspace Settings -> Build System 选择 Legacy Build System 即可。
内容的提问来源于stack exchange,提问作者Rujen Shakya
相关产品推荐
相关产品推荐

