8

I cannot see this documented anywhere — has anyine figured our how to use xcodebuild to build a propject for UIKIt for Mac (i.e. Catalyst)?

You can specify "-sdk iphoneos" vs "-sdk iphonesimulator" to toggle between those two targets, but "-sdk uikitformac" does not seem to work ("SDK not found"), despite Xcode itself using that nomenclature (e.g., it builds to a "Debug-uikitformac" folder, etc). i also tried different SDK values that might have made sense (such as "-sdk macabi"), but no avail.

Suggestions?

DrMickeyLauer
  • 4,455
  • 3
  • 31
  • 67
marc hoffman
  • 586
  • 1
  • 5
  • 14

3 Answers3

20

Add script file to your projects folder:

SCHEME=TestFramework \
ARCHS=~/Documents/Archives \

SCHEME is the name of build scheme in Xcode.

Lets build macCatalyst archive:

#----- Make macCatalyst archive
xcodebuild archive \
-scheme $SCHEME \
-archivePath $ARCHS/macCatalyst.xcarchive \
-sdk macosx \
SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES SUPPORTS_MACCATALYST=YES

Also you can add other platforms like iOS device or Simulator:

#----- Make iOS Simulator archive
xcodebuild archive \
-scheme $SCHEME \
-archivePath $ARCHS/simulator.xcarchive \
-sdk iphonesimulator \
SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES

#----- Make iOS device archive
xcodebuild archive \
-scheme $SCHEME \
-archivePath $ARCHS/iosdevice.xcarchive \
-sdk iphoneos \
SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES

To include everything in XCFramework use:

#----- Make XCFramework
xcodebuild -create-xcframework \
-framework $ARCHS/simulator.xcarchive/Products/Library/Frameworks/$SCHEME.framework \
-framework $ARCHS/iosdevice.xcarchive/Products/Library/Frameworks/$SCHEME.framework \
-framework $ARCHS/macCatalyst.xcarchive/Products/Library/Frameworks/$SCHEME.framework \
-output ~/Documents/$SCHEME.xcframework

After running you will find your XCFramework in your Documents folder.

marc-medley
  • 8,931
  • 5
  • 60
  • 66
  • 1
    This is the best way to build xcframeworks for macCatalyst. – venj Oct 23 '19 at 04:33
  • `SCHEME is the name of build scheme in Xcode.` What if I want to make a third party framework into an xcframework? I cannot use `SCHEME` in that case since it isn't actually a scheme in Xcode. – Pigpocket Jan 06 '21 at 18:51
10

Try:

xcodebuild -configuration "Debug" ARCHS="x86_64h" \
  -destination 'platform=macOS,variant=Mac Catalyst' \
  -project "MyApp.xcodeproj"

(note the extra 'h' on the architecture)

marc-medley
  • 8,931
  • 5
  • 60
  • 66
2

I used this to build a XCFramework that includes the Mac Catalyst framework

XCFramework and Mac Catalyst

gbacklin
  • 21
  • 1