facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
119.21k stars 24.33k forks source link

Cannot add WatchOS target to React Native App #30155

Closed MoonTahoe closed 4 years ago

MoonTahoe commented 4 years ago

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.

open-file

Inside the workspace I select the main project and click the + under targets.

targets

From here I select watchOS and Watch App for iOS App:

select-target

With the following settings:

create-watch-app

And I activate the target when asked:

activate-target

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:

first-error

There is some sort of problem Compiling Swift Sources?

If I try to run the WatchApp target in the simulator I get 47 errors:

errors

How can I resolve these errors and run a basic Hello World with React Native and Apple Watch?

Package Versions

lib version
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
github-actions[bot] commented 4 years ago
:warning: Missing Environment Information
:information_source: Your issue may be missing information about your development environment. You can obtain the missing information by running react-native info in a console.
MoonTahoe commented 4 years ago

react-native info command does't work. error Unreconized command "info".

Here are the versions for React Native, xCode, and macOS...

I don't have an Android environment setup yet, but react-native doctor does work and here are the results:

Common
 ✓ Node.js
 ✓ yarn
 ✓ npm
 ✓ Watchman - Used for watching changes in the filesystem when in development mode

Android
 ✖ JDK
   - Version found: N/A
   - Version supported: >= 8
 ✓ Android Studio - Required for building and installing your app on Android
 ✖ Android SDK - Required for building and installing your app on Android
   - Versions found: N/A
   - Version supported: Not Found
 ✖ ANDROID_HOME

iOS
 ✓ Xcode - Required for building and installing your app on iOS
 ✓ CocoaPods - Required for installing iOS dependencies
 ✓ ios-deploy - Required for installing your app on a physical device with the CLI
MoonTahoe commented 4 years ago

It seems like the React Native iOS app is written in Objective-C, and I am trying to add a WatchOS Target that uses Swift. If I make the WatchOS target Objective-C, I do not get any errors. Everything builds and runs as expected.

Is there a way to add a Swift Target to an Objective-C project? Can I add a WatchOS target that uses Swift to a React Native App?

MoonTahoe commented 4 years ago

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 🎉🥳