Sunday, August 7, 2022

Build iOS Framework using Xcode CLI




 


In this post we will use a script to create an Xcode library using the xcode CLI.


We start by installing the Xcode CLI tool:

xcode-select --install


In some cases you will need to point to the location of the Xcode, so instead, you will need to run the following command:


sudo xcode-select -s /my_apps/Xcode.app/Contents/Developer


Next, change directory to the root of the library and run the following script:


FRAMEWORK_NAME=MyFramework
SIMULATOR_ARCHIVE_PATH=./Output/${FRAMEWORK_NAME}-iphonesimulator.xcarchive
IOS_DEVICE_ARCHIVE_PATH=./Output/${FRAMEWORK_NAME}-iphoneos.xcarchive
FRAMEWORK_PATH=./Output/${FRAMEWORK_NAME}.xcframework

xcodebuild archive -scheme ${FRAMEWORK_NAME} -destination="iOS Simulator" -archivePath "${SIMULATOR_ARCHIVE_PATH}" -sdk iphonesimulator SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES
xcodebuild archive -scheme ${FRAMEWORK_NAME} -destination="iOS" -archivePath "${IOS_DEVICE_ARCHIVE_PATH}" -sdk iphoneos SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES
xcodebuild -create-xcframework \
-framework ${SIMULATOR_ARCHIVE_PATH}/Products/Library/Frameworks/${FRAMEWORK_NAME}.framework \
-framework ${IOS_DEVICE_ARCHIVE_PATH}/Products/Library/Frameworks/${FRAMEWORK_NAME}.framework \
-output "${FRAMEWORK_PATH}"


This runs for ~2 mintues, and finally create an xcframework file which can be used by other applications.




No comments:

Post a Comment