IOS 的 React Native 构建失败
Posted
技术标签:
【中文标题】IOS 的 React Native 构建失败【英文标题】:React native build fails for IOS 【发布时间】:2021-12-16 05:55:01 【问题描述】:过去两天我一直在为这个构建错误而苦苦挣扎,我的项目在 android 上运行良好,但我无法在 ios 上运行它。 我遵循了 IOS 的 react native 文档并安装了所有要求。 我正在使用 Mac OS Catalina,Xcode 12.4。
这是我的 Podfile:
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
platform :ios, '11.0'
target 'frontend' do
config = use_native_modules!
use_react_native!(
:path => config[:reactNativePath],
# to enable hermes on iOS, change `false` to `true` and then install pods
:hermes_enabled => false
)
target 'frontendTests' do
inherit! :complete
# Pods for testing
end
# Enables Flipper.
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable the next line.
use_flipper!()
post_install do |installer|
react_native_post_install(installer)
__apply_Xcode_12_5_M1_post_install_workaround(installer)
end
end
这是我收到的错误消息:
** BUILD FAILED **
The following build commands failed:
CpResource /Users/alibarznji/Desktop/Projects/grade_application/frontend/node_modules/react-native-vector-icons/Fonts/FontAwesome5_Brands.ttf /Users/alibarznji/Library/Developer/Xcode/DerivedData/frontend-dgqzfuyktcahthepzaqwwqkxxvej/Build/Products/Debug-iphonesimulator/frontend.app/FontAwesome5_Brands.ttf
CpResource /Users/alibarznji/Desktop/Projects/grade_application/frontend/node_modules/react-native-vector-icons/Fonts/FontAwesome5_Regular.ttf /Users/alibarznji/Library/Developer/Xcode/DerivedData/frontend-dgqzfuyktcahthepzaqwwqkxxvej/Build/Products/Debug-iphonesimulator/frontend.app/FontAwesome5_Regular.ttf
CpResource /Users/alibarznji/Desktop/Projects/grade_application/frontend/node_modules/react-native-vector-icons/Fonts/FontAwesome5_Solid.ttf /Users/alibarznji/Library/Developer/Xcode/DerivedData/frontend-dgqzfuyktcahthepzaqwwqkxxvej/Build/Products/Debug-iphonesimulator/frontend.app/FontAwesome5_Solid.ttf
CpResource /Users/alibarznji/Desktop/Projects/grade_application/frontend/src/assets/fonts/regular.ttf /Users/alibarznji/Library/Developer/Xcode/DerivedData/frontend-dgqzfuyktcahthepzaqwwqkxxvej/Build/Products/Debug-iphonesimulator/frontend.app/regular.ttf
(4 failures)
请注意,我的项目中没有使用 Font-Awesome,最后一行错误指向我的名为“常规”的 assets/fonts 文件夹不存在,我已将文件重命名为 K2D -Regular.ttf 之后我运行了命令“pod install”和“pod repo update”。我究竟做错了什么? 提前感谢您的帮助,谢谢。
【问题讨论】:
【参考方案1】:从错误中,我认为您正在为图标使用 react-native-vector 图标库,这些图标需要添加一些字体而这些字体丢失了。根据installation 指南,您必须在 info.plist 文件中添加字体规范,如下所示:
info.plist
<key>UIAppFonts</key>
<array>
<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>MaterialIcons.ttf</string>
<string>MaterialCommunityIcons.ttf</string>
<string>SimpleLineIcons.ttf</string>
<string>Octicons.ttf</string>
<string>Zocial.ttf</string>
<string>Fontisto.ttf</string>
</array>
【讨论】:
嘿,谢谢你的回复,我检查了我的 info.plist 文件,那些字体已经在那里,还有其他方法可以出错吗?如果 'pod' install 没有修复它,我该怎么办?删除 Xcode 目录中的 build 文件夹会有所帮助吗? 谢谢我的回答,你帮了大忙以上是关于IOS 的 React Native 构建失败的主要内容,如果未能解决你的问题,请参考以下文章
在 Mac M1 上 React Native ios 构建失败
React Native 和 RNFirebase iOS 版本构建失败