Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 11 Beta won't build because of WatchKit?

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

like image 229
jimijon Avatar asked Jun 07 '19 12:06

jimijon


3 Answers

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.

like image 107
ToniK Avatar answered Nov 07 '22 15:11

ToniK


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".

like image 40
user1988824 Avatar answered Nov 07 '22 13:11

user1988824


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.

like image 9
Manoj Kumar Chinikela Avatar answered Nov 07 '22 15:11

Manoj Kumar Chinikela