IOS 的 React 本机构建失败

React native build fails for IOS

过去两天我一直在为这个构建错误而苦苦挣扎,我的项目在 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 名称为 'regular' 的文件夹不存在,我已将文件重命名为 K2D-Regular.ttf,之后我有 运行 命令 'pod install' 和 'pod repo update'。我究竟做错了什么? 感谢您的提前帮助,谢谢。

从错误来看,我认为您使用的是 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>