在安装React Native时,在macOS Big Sur上出现"Undefined symbol: protocol descriptor for Swift.ExpressibleByFloatLiteral"问题。

33

我试图在我的系统上安装React Native,但发现它无法安装CocoaPods依赖项,而这是该模板所需的错误。

sudo arch -x86_64 gem install ffi可以解决此问题,但会出现event-config.h" file not found错误。

我更改了Pod文件中的Flipper版本为use_flipper!({'Flipper'=>'0.76.0'}),然后遇到了上述错误。如有任何帮助,请不吝赐教。

node version : 15.10.0
react-native version: 0.63.4
Xcode version: 12.4

以下是错误描述:

Showing Recent Messages

Could not find or use auto-linked library 'swiftCoreGraphics'
Could not find or use auto-linked library 'swiftUIKit'
Could not find or use auto-linked library 'swiftDarwin'
Could not find or use auto-linked library 'swiftFoundation'
Could not find or use auto-linked library 'swiftMetal'
Could not find or use auto-linked library 'swiftObjectiveC'
Could not find or use auto-linked library 'swiftCoreFoundation'
Could not find or use auto-linked library 'swiftDispatch'
Could not find or use auto-linked library 'swiftCoreImage'
Could not find or use auto-linked library 'swiftQuartzCore'
Could not find or use auto-linked library 'swiftCore'
Could not find or use auto-linked library 'swiftSwiftOnoneSupport'
Undefined symbol: protocol descriptor for Swift.ExpressibleByFloatLiteral
Undefined symbol: associated type descriptor for Swift.ExpressibleByIntegerLiteral.IntegerLiteralType

Undefined symbol: associated conformance descriptor for Swift.ExpressibleByIntegerLiteral.Swift.ExpressibleByIntegerLiteral.IntegerLiteralType: Swift._ExpressibleByBuiltinIntegerLiteral

Undefined symbol: method descriptor for Swift.ExpressibleByFloatLiteral.init(floatLiteral: A.FloatLiteralType) -> A

Undefined symbol: protocol descriptor for Swift.ExpressibleByIntegerLiteral
Undefined symbol: value witness table for Builtin.Int32
Undefined symbol: __swift_FORCE_LOAD_$_swiftCoreImage
Undefined symbol: associated type descriptor for Swift.ExpressibleByFloatLiteral.FloatLiteralType
Undefined symbol: __swift_FORCE_LOAD_$_swiftQuartzCore
Undefined symbol: __swift_FORCE_LOAD_$_swiftDispatch
Undefined symbol: method descriptor for Swift.ExpressibleByIntegerLiteral.init(integerLiteral: A.IntegerLiteralType) -> A
Undefined symbol: __swift_FORCE_LOAD_$_swiftCoreFoundation
Undefined symbol: protocol witness table for Swift.Int : Swift._ExpressibleByBuiltinIntegerLiteral in Swift
Undefined symbol: __swift_FORCE_LOAD_$_swiftObjectiveC
Undefined symbol: __swift_FORCE_LOAD_$_swiftCoreGraphics
Undefined symbol: _swift_getForeignTypeMetadata
Undefined symbol: __swift_FORCE_LOAD_$_swiftFoundation
Undefined symbol: associated conformance descriptor for Swift.ExpressibleByFloatLiteral.Swift.ExpressibleByFloatLiteral.FloatLiteralType: Swift._ExpressibleByBuiltinFloatLiteral
Undefined symbol: __swift_FORCE_LOAD_$_swiftUIKit
Undefined symbol: __swift_FORCE_LOAD_$_swiftMetal
Undefined symbol: Swift.Float.init(Swift.Double) -> Swift.Float
Undefined symbol: __swift_FORCE_LOAD_$_swiftDarwin
Undefined symbol: protocol witness table for Swift.Float : Swift._ExpressibleByBuiltinFloatLiteral in Swift

这个有更新了吗? - Pablo
这个评论(逐步)最终帮助了我...也许这会对其他人有所帮助 https://github.com/facebook/react-native/issues/31179#issuecomment-829536845 - Dror Bar
8个回答

53
如果您使用 M1 Mac,需要排除架构 arm64。请在 pod 文件末尾添加此代码。

You need to exclude architecture arm64 if you are using M1 mac. Please check this image

Also add this code at the end of the pod file

post_install do |installer|
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings["ONLY_ACTIVE_ARCH"] = "NO"
      end
    end
  end

运行 pod install,清理构建文件夹并重新启动构建即可解决问题。

更新:对于 xCode 13,请使用以下配置: 如果您遇到“在 react native xcode 13 中,Command PhaseScriptExecution 失败并显示非零退出代码”的问题,请执行以下操作:

在 react native xcode 13 中,Command PhaseScriptExecution 失败并显示非零退出代码


3
为什么这不是一个被接受的答案!我为这个问题苦苦挣扎了几个小时,而这个解决方案却很有效! - Nirmal Dalmia
我不需要添加podfile的内容。它运行得非常好! - Felipe Esteves
@AkilaDevinda,只需执行 brew install node 即可解决问题。 - Yurij
1
我想知道,在M1 Mac上构建时,为什么要排除arm64? - Yurij
1
@DrorBar 很高兴听到您解决了问题,希望其他人也能找到您发布的链接。 - Dipan Sharma
显示剩余7条评论

7

对我有效的方法是,只需添加这些排除的架构,如果你使用的是搭载M1芯片的Mac,那么你就会没问题了。

在此输入图片描述


2

我通过在Xcode项目中添加一个空的Swift文件来解决了这个问题。这样做的副作用是创建了一个桥接头文件,这使得我的项目编译成功。


2
如果您使用的是 M1 Mac:
  • 在 iOS 文件夹中运行 arch -x86_64 pod install
  • 使用 Rosetta 运行 Xcode
  • 进行清理构建
  • 再次运行

1

对我来说,我需要使用XCode创建一个Swift文件,然后自动创建桥接文件,接着我从debugreleaselibrary_search_paths中删除了以下行:"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)" "$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)"这样我的项目就能够编译了。 - alycecristines

0
Dipan的出色答案一开始对我有用,但由于某些不可控因素,我不得不更新一堆React库,结果它不再起作用了。
最终,我通过删除两个引用来解决了这个问题。
"\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\""

<我的项目名称>.xcodeproj/project.pbxproj文件中,我进行了修改。然后我再次运行了我的项目,它成功地通过了最后几个文件。

注意:为了充分披露,我不知道这个更改的后果会是什么


0

使用Dipan Sharma的解决方案后,我无法再为设备或“任何iOS设备”构建。对我有用的解决此问题的方法是仅在“任何iOS模拟器SDK”中排除arm64,而不是在更高级别上排除它。即使从排除的架构的更高级别中删除了arm64,也无法再次为设备和“任何iOS设备”构建项目。必须从我的git中提取旧的项目文件。


苹果硅M1上工作的“排除架构”设置


-2

这是因为您的项目包含了Swift和Objective C两种框架/库。

如果您在项目中已经看到了Objective C文件,则需要添加一个Swift文件;如果您在项目中已经看到了Swift文件,则需要添加一个Objective C文件。选择那些出现上述错误的目标。

这一步将要求创建一个桥接头文件。请创建桥接头文件并编译运行。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接