I have developed a couple of watch apps and I am getting the hang of it, but when I try to add a watch os target to a React Native App I get 47 errors that I do not understand.
I am attempting to follow this tutorial – How to add an Apple Watch Extension To your react native application.
Steps to Reproduce
1. Create a new React Native Project
First, I created a new React Native Project. (success ✅)
react-native init RNWithAppleWatch
2. Build and Run the React Native Project
Then I can build and run the project. (success ✅)
cd RNWtihAppleWatch; npm run ios;
3. Open the Project Workspace and add a Target
Next, I open the workspace file. At this point the React Native app builds and runs from xCode without issue too.
Inside the workspace I select the main project and click the +
under targets.
From here I select watchOS
and Watch App for iOS App
:
With the following settings:
And I activate the target when asked:
And the Target is created.
6. Run the Watch Target
This is where the problems begin to surface. The first thing I notice is there is one error in the WatchApp Extension
after the target is created:
There is some sort of problem Compiling Swift Sources?
If I try to run the WatchApp
target in the simulator I get 47 errors:
How can I resolve these errors and run a basic Hello World
with React Native and Apple Watch?
Package Versions
- react-native 0.63.3
- xCode 12.0.1
- macOS Catalina 10.15.6
Full Error Text
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
2
Answers
I was able to resolve this issue by changing the Library Search Paths Build Setting.
In your project select the Watch Extension Target, then Build Settings Menu, and find the Library Search Paths setting. (You need to make sure the "All" filter is selected or you will not see this setting). In it's value you'll see two links, use the first one only... Set the value ov Library Search Paths to:
"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)"
This worked for me 🎉🥳
When I came across this, the path @Tabbyofjudah suggested was already present in the list,
I actually solved this by deleting the contents of Library Search Paths for the watchOS extension. Leaving it looking like this:
And my project now builds (not just as a bodge, all the way to App Store Connect). Hope this is useful to someone.