无法将 WatchOS 目标添加到 React Native App

Cannot add WatchOS target to React Native App

我已经开发了几个手表应用程序并且我正在掌握它,但是当我尝试将手表 os 目标添加到 React Native 应用程序时,我收到 47 个我不明白的错误.

我正在尝试关注此 tutorial - How to add an Apple Watch Extension To your react native application

重现步骤

1。创建一个新的 React Native 项目

首先,我创建了一个新的 React Native 项目。 (成功✅)

react-native init RNWithAppleWatch

2。构建并 运行 React Native 项目

然后我可以构建 运行 项目。 (成功✅)

cd RNWtihAppleWatch; npm run ios;

3。打开项目工作区并添加一个目标

接下来,我打开工作区文件。在这一点上,React Native 应用程序从 xCode 构建和 运行s 也没有问题。

在工作区内,我 select 主项目并单击目标下的 +

从这里我 select watchOSWatch App for iOS App:

具有以下设置:

当被问到时我激活了目标:

目标已创建。

6. 运行 监视目标

这就是问题开始浮出水面的地方。我注意到的第一件事是创建目标后 WatchApp Extension 中有一个错误:

编译 Swift 源代码时出现某种问题?

如果我尝试 运行 模拟器中的 WatchApp 目标,我会收到 47 个错误:

我如何解决这些错误以及如何使用 React Native 和 Apple Watch 运行 基本 Hello World

包版本

完整错误文本

Ld /Users/xxx/Library/Developer/Xcode/DerivedData/RNWithAppleWatch-axogcnukcxagprhcahugtcdatqdx/Build/Intermediates.noindex/RNWithAppleWatch.build/Debug-watchsimulator/WatchApp\ Extension.build/Objects-normal/arm64/Binary/WatchApp\ Extension normal arm64 (in target 'WatchApp Extension' from project 'RNWithAppleWatch')
    cd /Users/xxx/Projects/learning/RNWithAppleWatch/ios
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target arm64-apple-watchos7.0-simulator -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator7.0.sdk -L/Users/xxx/Library/Developer/Xcode/DerivedData/RNWithAppleWatch-axogcnukcxagprhcahugtcdatqdx/Build/Products/Debug-watchsimulator -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/watchsimulator -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.0/watchsimulator -F/Users/xxx/Library/Developer/Xcode/DerivedData/RNWithAppleWatch-axogcnukcxagprhcahugtcdatqdx/Build/xxx/Debug-watchsimulator -filelist /Users/xxx/Library/Developer/Xcode/DerivedData/RNWithAppleWatch-axogcnukcxagprhcahugtcdatqdx/Build/Intermediates.noindex/RNWithAppleWatch.build/Debug-watchsimulator/WatchApp\ Extension.build/Objects-normal/arm64/WatchApp\ Extension.LinkFileList -Xlinker -rpath -Xlinker /usr/lib/swift -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @executable_path/../../Frameworks -dead_strip -Xlinker -object_path_lto -Xlinker /Users/xxx/Library/Developer/Xcode/DerivedData/RNWithAppleWatch-axogcnukcxagprhcahugtcdatqdx/Build/Intermediates.noindex/RNWithAppleWatch.build/Debug-watchsimulator/WatchApp\ Extension.build/Objects-normal/arm64/WatchApp\ Extension_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -Xlinker -objc_abi_version -Xlinker 2 -fapplication-extension -fobjc-link-runtime -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/watchsimulator -L/usr/lib/swift -Xlinker -add_ast_path -Xlinker /Users/xxx/Library/Developer/Xcode/DerivedData/RNWithAppleWatch-axogcnukcxagprhcahugtcdatqdx/Build/Intermediates.noindex/RNWithAppleWatch.build/Debug-watchsimulator/WatchApp\ Extension.build/Objects-normal/arm64/WatchApp_Extension.swiftmodule -e _WKExtensionMain -framework WatchKit -Xlinker -sectcreate -Xlinker __TEXT -Xlinker __entitlements -Xlinker /Users/xxx/Library/Developer/Xcode/DerivedData/RNWithAppleWatch-axogcnukcxagprhcahugtcdatqdx/Build/Intermediates.noindex/RNWithAppleWatch.build/Debug-watchsimulator/WatchApp\ Extension.build/WatchApp\ Extension.appex-Simulated.xcent -Xlinker -dependency_info -Xlinker /Users/xxx/Library/Developer/Xcode/DerivedData/RNWithAppleWatch-axogcnukcxagprhcahugtcdatqdx/Build/Intermediates.noindex/RNWithAppleWatch.build/Debug-watchsimulator/WatchApp\ Extension.build/Objects-normal/arm64/WatchApp\ Extension_dependency_info.dat -o /Users/xxx/Library/Developer/Xcode/DerivedData/RNWithAppleWatch-axogcnukcxagprhcahugtcdatqdx/Build/Intermediates.noindex/RNWithAppleWatch.build/Debug-watchsimulator/WatchApp\ Extension.build/Objects-normal/arm64/Binary/WatchApp\ Extension

ld: warning: Could not find or use auto-linked library 'swiftCore'
ld: warning: Could not find or use auto-linked library 'swiftHomeKit'
ld: warning: Could not find or use auto-linked library 'swiftCoreGraphics'
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 'swiftFoundation'
ld: warning: Could not find or use auto-linked library 'swiftsimd'
ld: warning: Could not find or use auto-linked library 'swiftObjectiveC'
ld: warning: Could not find or use auto-linked library 'swiftSwiftOnoneSupport'
ld: warning: Could not find or use auto-linked library 'swiftWatchKit'
ld: warning: Could not find or use auto-linked library 'swiftSceneKit'
ld: warning: Could not find or use auto-linked library 'swiftDispatch'
ld: warning: Could not find or use auto-linked library 'swiftMapKit'
ld: warning: Could not find or use auto-linked library 'swiftCoreFoundation'
ld: warning: Could not find or use auto-linked library 'swiftCoreLocation'
Undefined symbols for architecture arm64:
  "value witness table for Builtin.Int64", referenced from:
      full type metadata for __C.CLKComplicationPrivacyBehavior in ComplicationController.o
  "nominal type descriptor for Foundation.Date", referenced from:
      _symbolic _____Sg 10Foundation4DateV in ComplicationController.o
  "_swift_getForeignTypeMetadata", referenced from:
      type metadata accessor for __C.CLKComplicationPrivacyBehavior in ComplicationController.o
  "static (extension in Foundation):Swift.Array._unconditionallyBridgeFromObjectiveC(__C.NSArray?) -> [A]", referenced from:
      @objc WatchApp_Extension.ComplicationController.handleSharedComplicationDescriptors([__C.CLKComplicationDescriptor]) -> () in ComplicationController.o
  "(extension in Foundation):Swift.Array._bridgeToObjectiveC() -> __C.NSArray", referenced from:
      reabstraction thunk helper from @escaping @callee_unowned @convention(block) (@unowned __C.NSArray) -> () to @escaping @callee_guaranteed (@guaranteed [__C.CLKComplicationDescriptor]) -> () in ComplicationController.o
      reabstraction thunk helper from @escaping @callee_unowned @convention(block) (@unowned __C.NSArray?) -> () to @escaping @callee_guaranteed (@guaranteed [__C.CLKComplicationTimelineEntry]?) -> () in ComplicationController.o
  "_swift_allocObject", referenced from:
      @objc WatchApp_Extension.ComplicationController.getComplicationDescriptors(handler: ([__C.CLKComplicationDescriptor]) -> ()) -> () in ComplicationController.o
      @objc WatchApp_Extension.ComplicationController.getTimelineEndDate(for: __C.CLKComplication, withHandler: (Foundation.Date?) -> ()) -> () in ComplicationController.o
      @objc WatchApp_Extension.ComplicationController.getPrivacyBehavior(for: __C.CLKComplication, withHandler: (__C.CLKComplicationPrivacyBehavior) -> ()) -> () in ComplicationController.o
      @objc WatchApp_Extension.ComplicationController.getCurrentTimelineEntry(for: __C.CLKComplication, withHandler: (__C.CLKComplicationTimelineEntry?) -> ()) -> () in ComplicationController.o
      @objc WatchApp_Extension.ComplicationController.getTimelineEntries(for: __C.CLKComplication, after: Foundation.Date, limit: Swift.Int, withHandler: ([__C.CLKComplicationTimelineEntry]?) -> ()) -> () in ComplicationController.o
      @objc WatchApp_Extension.ComplicationController.getLocalizableSampleTemplate(for: __C.CLKComplication, withHandler: (__C.CLKComplicationTemplate?) -> ()) -> () in ComplicationController.o
  "Swift.String.init(_builtinStringLiteral: Builtin.RawPointer, utf8CodeUnitCount: Builtin.Word, isASCII: Builtin.Int1) -> Swift.String", referenced from:
      WatchApp_Extension.ComplicationController.getComplicationDescriptors(handler: ([__C.CLKComplicationDescriptor]) -> ()) -> () in ComplicationController.o

我能够通过更改 库搜索路径 构建设置来解决此问题。

在您的项目中 select Watch Extension Target,然后是 Build Settings Menu,然后找到 Library Search Paths 设置。 (您需要确保“全部”过滤器已 selected 否则您将看不到此设置)。在它的值中,您会看到两个链接,仅使用第一个链接...将值 ov Library Search Paths 设置为:"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)"

这对我有用

当我遇到这个时,@Tabbyofjudah 建议的路径已经存在于列表中,

我实际上通过删除 watchOS 扩展的库搜索路径的内容解决了这个问题。让它看起来像这样:

现在我的项目正在构建(不只是作为一个障碍物,一直到 App Store Connect)。希望这对某人有用。