17

Worked on Xcode 10. Now in the beta I can't build I keep getting this error:

a "WatchKit" is not available when building for iOS Simulator. Consider using #if !os(iOS) to conditionally import this framework.

enter image description here

Jayprakash Dubey
  • 35,723
  • 18
  • 170
  • 177
jimijon
  • 2,046
  • 1
  • 20
  • 39

4 Answers4

18

I had the same issue for one swift file in the WatchKit Extension. It turned out that it was a member of both the iOS app and the WatchKit Extension. I unticked the iOS app in the target membership section for the file so that it only belongs to the WatchKit Extension target. Now the project builds successfully.

ToniK
  • 611
  • 6
  • 5
11

Some of the functionality to communicate between the Apple watch with the iPhone/iPad used to be implemented within the WatchKit framework. But at some point it got moved into the WatchKitConnectivity framework.

If you look in your Target's "Build Phase" -> "Link Binary With Libraries" section, you will see the "WatchKit.framework" with "Optional" status. iOS13+ has become more "strict" so it won't build unless I completely remove the "WatchKit.framework", and instead add "WatchConnectivity.framework".

Also make sure your iPhone/iPad code refers use "import WatchConnectivity" instead of "import WatchKit".

user1988824
  • 2,947
  • 2
  • 22
  • 27
  • This solution WORKED FOR ME we need to REMOVE the "WatchKit.framework" in selected Target "Build Phase" -> Link Binary Section. – sumanthkodi Mar 30 '20 at 07:52
9

We need to use "Conditional Imports" to resolve the issue.

Replace the import WatchKit header with the below code :

#if !os(iOS)
import WatchKit
#endif

This resolved my issue and build successfully in iOS 13.

barbsan
  • 3,418
  • 11
  • 21
  • 28
  • well yes, that works too, but this was an upgrade and the old Xcode was evidently not as strict. My resetting file targets and a couple of files fixed it for me. – jimijon Jun 12 '19 at 16:50
8

Xcode 11 removes WatchKit from the iOS SDK. From release notes:

The WatchKit framework is no longer included in the iOS SDK. If you’re using WatchKit APIs from iOS, you need to remove this use. The WatchKit framework remains available on watchOS. If you’re using WatchKit APIs from iOS to infer availability of features on the paired Apple Watch, include information about your use case when you submit feedback to Feedback Assistant. (49707950)

This includes Cordova plugins that reference WatchKit in plugin.xml:

<framework src="WatchKit.framework" />

The above line will add WatchKit as a framework for the iOS app target. You'll need to remove this and add WatchKit only to Watch target of your app.

trebor
  • 903
  • 1
  • 12
  • 23