React Native 0.62 iOS 错误 Undefined symbol: associated type descriptor for FloatLiteralType

React Native 2020-05-01 阅读 462 评论 0

问题描述

React Native 0.61.5 升级到 0.62.2,Xcode 编译时出现一下错误。

ld: warning: Could not find or use auto-linked library 'swiftObjectiveC'
ld: warning: Could not find or use auto-linked library 'swiftCoreGraphics'
ld: warning: Could not find or use auto-linked library 'swiftCore'
ld: warning: Could not find or use auto-linked library 'swiftQuartzCore'
ld: warning: Could not find or use auto-linked library 'swiftCoreFoundation'
ld: warning: Could not find or use auto-linked library 'swiftCompatibility50'
ld: warning: Could not find or use auto-linked library 'swiftDarwin'
ld: warning: Could not find or use auto-linked library 'swiftUIKit'
ld: warning: Could not find or use auto-linked library 'swiftDispatch'
ld: warning: Could not find or use auto-linked library 'swiftFoundation'
ld: warning: Could not find or use auto-linked library 'swiftCoreImage'
ld: warning: Could not find or use auto-linked library 'swiftCompatibilityDynamicReplacements'
ld: warning: Could not find or use auto-linked library 'swiftMetal'
ld: warning: Could not find or use auto-linked library 'swiftSwiftOnoneSupport'
Undefined symbols for architecture x86_64:
  "associated type descriptor for FloatLiteralType", referenced from:
      protocol conformance descriptor for __C.YGValue : Swift.ExpressibleByFloatLiteral in YogaKit in libYogaKit.a(YGLayoutExtensions.o)
  "associated type descriptor for IntegerLiteralType", referenced from:
      protocol conformance descriptor for __C.YGValue : Swift.ExpressibleByIntegerLiteral in YogaKit in libYogaKit.a(YGLayoutExtensions.o)
  "value witness table for Builtin.Int32", referenced from:
      full type metadata for __C.YGUnit in libYogaKit.a(YGLayoutExtensions.o)
  "protocol witness table for Swift.Float : Swift._ExpressibleByBuiltinFloatLiteral in Swift", referenced from:
      associated type witness table accessor for FloatLiteralType : Swift._ExpressibleByBuiltinFloatLiteral in __C.YGValue : Swift.ExpressibleByFloatLiteral in YogaKit in libYogaKit.a(YGLayoutExtensions.o)
  "protocol witness table for Swift.Int : Swift._ExpressibleByBuiltinIntegerLiteral in Swift", referenced from:
      associated type witness table accessor for IntegerLiteralType : Swift._ExpressibleByBuiltinIntegerLiteral in __C.YGValue : Swift.ExpressibleByIntegerLiteral in YogaKit in libYogaKit.a(YGLayoutExtensions.o)
  "protocol descriptor for Swift.ExpressibleByFloatLiteral", referenced from:
      protocol conformance descriptor for __C.YGValue : Swift.ExpressibleByFloatLiteral in YogaKit in libYogaKit.a(YGLayoutExtensions.o)
  "method descriptor for Swift.ExpressibleByFloatLiteral.init(floatLiteral: A.FloatLiteralType) -> A", referenced from:
      protocol conformance descriptor for __C.YGValue : Swift.ExpressibleByFloatLiteral in YogaKit in libYogaKit.a(YGLayoutExtensions.o)
  "associated conformance descriptor for Swift.ExpressibleByFloatLiteral.FloatLiteralType: Swift._ExpressibleByBuiltinFloatLiteral", referenced from:
      protocol conformance descriptor for __C.YGValue : Swift.ExpressibleByFloatLiteral in YogaKit in libYogaKit.a(YGLayoutExtensions.o)
  "protocol descriptor for Swift.ExpressibleByIntegerLiteral", referenced from:
      protocol conformance descriptor for __C.YGValue : Swift.ExpressibleByIntegerLiteral in YogaKit in libYogaKit.a(YGLayoutExtensions.o)
  "method descriptor for Swift.ExpressibleByIntegerLiteral.init(integerLiteral: A.IntegerLiteralType) -> A", referenced from:
      protocol conformance descriptor for __C.YGValue : Swift.ExpressibleByIntegerLiteral in YogaKit in libYogaKit.a(YGLayoutExtensions.o)
  "associated conformance descriptor for Swift.ExpressibleByIntegerLiteral.IntegerLiteralType: Swift._ExpressibleByBuiltinIntegerLiteral", referenced from:
      protocol conformance descriptor for __C.YGValue : Swift.ExpressibleByIntegerLiteral in YogaKit in libYogaKit.a(YGLayoutExtensions.o)
  "__swift_FORCE_LOAD_$_swiftCompatibility50", referenced from:
      __swift_FORCE_LOAD_$_swiftCompatibility50_$_YogaKit in libYogaKit.a(YGLayoutExtensions.o)
     (maybe you meant: __swift_FORCE_LOAD_$_swiftCompatibility50_$_YogaKit)
  "__swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements", referenced from:
      __swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements_$_YogaKit in libYogaKit.a(YGLayoutExtensions.o)
     (maybe you meant: __swift_FORCE_LOAD_$_swiftCompatibilityDynamicReplacements_$_YogaKit)
  "_swift_getForeignTypeMetadata", referenced from:
      type metadata accessor for __C.YGValue in libYogaKit.a(YGLayoutExtensions.o)
      type metadata accessor for __C.YGUnit in libYogaKit.a(YGLayoutExtensions.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

解决方案

以下总结2种处理方法。

1. 参考官方的升级代码

参考官方的 upgrade helper webtool 工具,查看 git diff https://react-native-community.github.io/upgrade-helper/?from=0.61.5&to=0.62.2,修改项目的代码。主要是 ios/RnDiffApp.xcodeproj/project.pbxprojios/Podfile 的改动。

2. 按照以下步骤修改

修改前,尽量先提交本地的内容,或者备份一下。

2.1 为项目添加 Swift

在项目下新建一个 swift 文件


选择 Swift File,填写任意的一个文件名称,在 Would you like to configure an Objective-C bridging header? 弹出框中,选择 Don't Create

创建文件后,即可删除。

选择 Move to Trash

2.2 添加 LIBRARY_SEARCH_PATHS

在 Procjet -> Build Settings -> Library Search Paths。分别添加:

"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)"

"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)"

"$(inherited)" 

2.3 设置 Dead Code Stripping 为 YES

在 Xcode 中,依次选择 PROJECT -> Build Settings -> LInking -> Dead Code Stringpping,设置为 YES,然后重新编译。

2.4 添加 LD_RUNPATH_SEARCH_PATHS

如果前面3步设置好了,运行 Xcode 后,项目可以启动,但是会奔溃,还需要设置 LD_RUNPATH_SEARCH_PATHS

在 Procjet -> Build Settings -> Runpath Search Paths。添加 /usr/lib/swift $(inherited)

最后 Clean Build Folder 重新编译。

最后更新 2020-05-01
MIP.watch('startSearch', function (newVal, oldVal) { if(newVal) { var keyword = MIP.getData('keyword'); console.log(keyword); // 替换当前历史记录,新增 MIP.viewer.open('/s/' + keyword, {replace: true}); setTimeout(function () { MIP.setData({startSearch: false}) }, 1000); } }); MIP.watch('goHome', function (newVal, oldVal) { MIP.viewer.open('/', {replace: false}); });