Skip to content

Instantly share code, notes, and snippets.

@alexcohn
Created October 10, 2020 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexcohn/53fb9e93699080f158b5721888edd578 to your computer and use it in GitHub Desktop.
Save alexcohn/53fb9e93699080f158b5721888edd578 to your computer and use it in GitHub Desktop.
build_xcframework.sh
#!/bin/sh
cd $(dirname $0)
# set framework name or read it from project by this variable
FRAMEWORK_NAME=$1
#xcframework path
FRAMEWORK_PATH="../${FRAMEWORK_NAME}.xcframework"
if [ -e ${FRAMEWORK_PATH} ]; then
echo "${FRAMEWORK_PATH} exists"
if [ "$2" = "force" ]; then
rm -r ${FRAMEWORK_PATH} || exit 1
else
exit 0
fi
fi
# set framework namefolder
BUILD_FOLDER_NAME=$(mktemp -d -t "${FRAMEWORK_NAME}")
# set path for iOS simulator archive
SIMULATOR_ARCHIVE_PATH="${BUILD_FOLDER_NAME}/simulator.xcarchive"
# set path for iOS device archive
IOS_DEVICE_ARCHIVE_PATH="${BUILD_FOLDER_NAME}/iOS.xcarchive"
echo "Archiving ${FRAMEWORK_NAME}"
xcodebuild archive -scheme ${FRAMEWORK_NAME} -destination="iOS Simulator" -archivePath "${SIMULATOR_ARCHIVE_PATH}" -sdk iphonesimulator SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES || exit 1
xcodebuild archive -scheme ${FRAMEWORK_NAME} -destination="iOS" -archivePath "${IOS_DEVICE_ARCHIVE_PATH}" -sdk iphoneos SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES || exit 1
#Creating XCFramework
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}" || exit 1
rm -rf "${BUILD_FOLDER_NAME}"
@alexcohn
Copy link
Author

alexcohn commented Oct 10, 2020

xcodebuild -create-xcframework embeds .gitkeep files that cause warning in the build of dependents

@alexcohn
Copy link
Author

@AbhijitPatilSafexpay
Copy link

I am getting this following error UniversalBuilds.build does not contain an Xcode project, workspace or package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment