Xcode 11 Beta won't build because of WatchKit?
Asked Answered
M

5

18

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

Mukluk answered 7/6, 2019 at 12:32 Comment(0)
C
19

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.

Cyclo answered 7/6, 2019 at 16:43 Comment(0)
S
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".

Succentor answered 20/9, 2019 at 11:42 Comment(1)
This solution WORKED FOR ME we need to REMOVE the "WatchKit.framework" in selected Target "Build Phase" -> Link Binary Section.Culminant
B
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.

Brash answered 10/6, 2019 at 6:9 Comment(1)
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.Mukluk
S
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.

Santasantacruz answered 25/9, 2019 at 17:35 Comment(1)
This answer goes exactly in the direction of what causes the issue, therefore the best!Mayers
T
0

I had <WatchKit/WatchKit.h> in the InterfaceController.h in WatchKitExtension, as it must be. I unticked the iOS "Test" target in the target memberships for the InterfaceController.m file and the error went away. Special thanks to ToniK for directing me there.

Tellurion answered 29/9, 2023 at 22:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.