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

Tab*_*dah 6 xcode ios apple-watch react-native

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

我正在尝试遵循本教程 - 如何向您的本机应用程序添加 Apple Watch 扩展

重现步骤

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

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

react-native init RNWithAppleWatch
Run Code Online (Sandbox Code Playgroud)

2. 构建并运行 React Native 项目

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

cd RNWtihAppleWatch; npm run ios;
Run Code Online (Sandbox Code Playgroud)

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

接下来,我打开工作区文件。此时 React Native 应用程序从 xCode 构建和运行也没有问题。

开放工作区

在工作区中,我选择主项目并单击+下方的目标。

目标

从这里我选择watchOSWatch App for iOS App

选择目标

使用以下设置:

创建手表应用

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

激活目标

并创建了目标。

6. 运行观察目标

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

第一个错误

编译 Swift Sources 有什么问题吗?

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

错误

如何解决这些错误并Hello World使用 React Native 和 Apple Watch运行基本程序?

包版本

  • 反应原生 0.63.3
  • 代码 12.0.1
  • macOS Catalina 10.15.6

完整的错误文本

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
Run Code Online (Sandbox Code Playgroud)

Dee*_*eBo 8

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

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

空搜索路径

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


Tab*_*dah 5

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

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

这对我有用