Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using `xcodebuild` to do a command line builds for Catalyst/UIKit for Mac?

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?

like image 806
marc hoffman Avatar asked Jul 10 '19 20:07

marc hoffman


People also ask

What are macOS command line tools?

The Command Line Tools Package is a small self-contained package available for download separately from Xcode and that allows you to do command line development in macOS. It consists of the macOS SDK and command-line tools such as Clang, which are installed in the /Library/Developer/CommandLineTools directory.

How do I pass command line arguments in Xcode?

Right click the executable in your Xcode project and pick "Get Info". Then pick the "arguments" tab and you can set arguments to pass when you run or debug your program from inside Xcode. Go to the Product menu, select "Edit Scheme", then select the arguments tab and add the arguments there.

How do I run Xcode from command line app?

go to the 'Info' tab and in a menu 'Executable' choose 'Other...' in file window go to search input field and type 'terminal' and click on its icon when you find it. Now you should see 'Terminal. app' in 'Executable' field.


2 Answers

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.

like image 133
Nikolay Tabunchenko Avatar answered Oct 18 '22 08:10

Nikolay Tabunchenko


Try:

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

(note the extra 'h' on the architecture)

like image 33
Rodrigo Gomez-Palacio Avatar answered Oct 18 '22 07:10

Rodrigo Gomez-Palacio