修改Podfile后构建项目出现'Unrecognized font family 'Lato-Regular''错误求助
解决
Unrecognized font family 'Lato-Regular'错误问题 问题背景
构建项目时触发Unrecognized font family 'Lato-Regular'错误,但项目内未主动引用该字体——全局搜索无相关记录。尝试过清理构建文件夹、将字体添加到info.plist均无效。错误出现在修改Podfile之后,修改代码如下:
installer.pods_project.targets.each do |target| if target.name == "React-Core.common-AccessibilityResources" target.remove_from_project
注意:这段代码不可删除,移除后项目无法完成归档。
当前info.plist中UIAppFonts配置:
<key>UIAppFonts</key> <array> <string>Kufam-SemiBoldItalic.ttf</string> <string>Lato-Bold.ttf</string> <string>Lato-BoldItalic.ttf</string> <string>Lato-Italic.ttf</string> <string>Lato-Regular.ttf</string> <string>AntDesign.ttf</string> <string>Entypo.ttf</string> <string>EvilIcons.ttf</string> <string>Feather.ttf</string> <string>FontAwesome.ttf</string> <string>FontAwesome5_Brands.ttf</string> <string>FontAwesome5_Regular.ttf</string> <string>FontAwesome5_Solid.ttf</string> <string>Foundation.ttf</string> <string>Ionicons.ttf</string> <string>MaterialCommunityIcons.ttf</string> <string>MaterialIcons.ttf</string> <string>Octicons.ttf</string> <string>SimpleLineIcons.ttf</string> <string>Zocial.ttf</string> </array>
可行解决方法
- 核对字体文件内部名称:用Font Book打开
Lato-Regular.ttf,查看其实际字体家族名称,可能与文件名不一致。如果内部名称不是Lato-Regular,需同步修改info.plist中的对应条目,或确保项目中引用的是正确的家族名。 - 修复Podfile修改的资源关联:移除
React-Core.common-AccessibilityResources可能破坏了Pods项目的字体资源绑定,可修改Podfile补充资源关联逻辑:installer.pods_project.targets.each do |target| if target.name == "React-Core.common-AccessibilityResources" target.remove_from_project end # 替换为你的项目Target名称,确保字体资源被添加到主目标 if target.name == "YourMainTargetName" font_file = installer.pods_project.files.find { |f| f.path.end_with?("Lato-Regular.ttf") } target.resources_build_phase.add_file_reference(font_file) if font_file end end
修改后执行pod install重新安装依赖。
- 确认字体资源已加入拷贝阶段:检查Xcode的
Build Phases->Copy Bundle Resources,确保Lato-Regular.ttf在列表中。若未添加,手动拖入该文件到这个阶段。 - 彻底清理缓存后重建:执行
pod deintegrate移除现有Pods,再pod install重新安装;同时删除Xcode的Derived Data(路径:Xcode -> 偏好设置 -> 位置 -> Derived Data),重启Xcode后重新构建项目。 - 排查第三方依赖的隐式引用:在Pods目录下执行
grep -r "Lato-Regular" ./Pods,查找是否有第三方库在隐式引用该字体。找到来源后,可为该库补充字体资源,或在Podfile中配置其资源打包规则。
内容的提问来源于stack exchange,提问作者Medic305
相关产品推荐
相关产品推荐

