I am relatively new to iOS and have been trying really hard to diagnose and find a way to start generating XCFramework instead of .Framework that was being built earlier until xCode 10.
I have went through many different blogs and answers on SO as well but could not find a solution to my issue. I need to build XCFramework with support for both iOS device as well as iOS Simulator on M1 architecture.
I have pasted below, the old as well as the new build scripts that I have been experimenting with.
OLD SCRIPT:
set -e
# If we're already inside this script then abort
`if [ -n "$RW_MULTIPLATFORM_BUILD_IN_PROGRESS" ]; then
exit 0
fi
export RW_MULTIPLATFORM_BUILD_IN_PROGRESS=1
RW_FRAMEWORK_NAME=${PROJECT_NAME}
RW_INPUT_STATIC_LIB="lib${PROJECT_NAME}.a"
RW_FRAMEWORK_LOCATION="${BUILT_PRODUCTS_DIR}/${RW_FRAMEWORK_NAME}.framework"
function build_static_library {
# Will rebuild the static library as specified
# build_static_library sdk
xcrun xcodebuild -project "${PROJECT_FILE_PATH}" \
-target "${TARGET_NAME}" \
-configuration "${CONFIGURATION}" \
-sdk "${1}" \
ONLY_ACTIVE_ARCH=NO \
BUILD_DIR="${BUILD_DIR}" \
OBJROOT="${OBJROOT}/DependentBuilds" \
BUILD_ROOT="${BUILD_ROOT}" \
SYMROOT="${SYMROOT}" $ACTION
}`
`function make_fat_library {
# Will smash 2 static libs together
# make_fat_library in1 in2 out
xcrun lipo -create "${1}" "${2}" -output "${3}"
}`
# 1 - Extract the platform (iphoneos/iphonesimulator) from the SDK name
`if [[ "$SDK_NAME" =~ ([A-Za-z]+) ]]; then
RW_SDK_PLATFORM=${BASH_REMATCH[1]}
else
echo "Could not find platform name from SDK_NAME: $SDK_NAME"
exit 1
fi`
# 2 - Extract the version from the SDK
`if [[ "$SDK_NAME" =~ ([0-9]+.*$) ]]; then
RW_SDK_VERSION=${BASH_REMATCH[1]}
else
echo "Could not find sdk version from SDK_NAME: $SDK_NAME"
exit 1
fi`
# 3 - Determine the other platform
`if [ "$RW_SDK_PLATFORM" == "iphoneos" ]; then
RW_OTHER_PLATFORM=iphonesimulator
else
RW_OTHER_PLATFORM=iphoneos
fi`
# 4 - Find the build directory
`if [[ "$BUILT_PRODUCTS_DIR" =~ (.*)$RW_SDK_PLATFORM$ ]]; then
RW_OTHER_BUILT_PRODUCTS_DIR="${BASH_REMATCH[1]}${RW_OTHER_PLATFORM}"
else
echo "Could not find other platform build directory."
exit 1
fi`
# Build the other platform.
`build_static_library "${RW_OTHER_PLATFORM}${RW_SDK_VERSION}"
`
# If we're currently building for iphonesimulator, then need to rebuild
# to ensure that we get both i386 and x86_64
`if [ "$RW_SDK_PLATFORM" == "iphonesimulator" ]; then
build_static_library "${SDK_NAME}"
fi`
# Join the 2 static libs into 1 and push into the .framework
`make_fat_library "${BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}" \
"${RW_OTHER_BUILT_PRODUCTS_DIR}/${RW_INPUT_STATIC_LIB}" \
"${RW_FRAMEWORK_LOCATION}/Versions/A/${RW_FRAMEWORK_NAME}"
`
# Ensure that the framework is present in both platform's build directories
`cp -a "${RW_FRAMEWORK_LOCATION}/Versions/A/${RW_FRAMEWORK_NAME}" \
"${RW_OTHER_BUILT_PRODUCTS_DIR}/${RW_FRAMEWORK_NAME}.framework/Versions/A/${RW_FRAMEWORK_NAME}"
`
# Copy the framework to the user's desktop
`ditto "${RW_FRAMEWORK_LOCATION}" "${HOME}/Desktop/${RW_FRAMEWORK_NAME}.framework"
`
NEW SCRIPT THAT I AM USING TO GENERATE XCFRAMEWORK
SIMULATOR_ARCHIVE_PATH="${BUILD_DIR}/${CONFIGURATION}/${FRAMEWORK_NAME}-iphonesimulator.xcarchive"
DEVICE_ARCHIVE_PATH="${BUILD_DIR}/${CONFIGURATION}/${FRAMEWORK_NAME}-iphoneos.xcarchive"
echo "Simulator Path:$SIMULATOR_ARCHIVE_PATH"
echo "Device Archive Path: $DEVICE_ARCHIVE_PATH"
echo "Build DIR: $BUILD_DIR"
echo "Configuration Path: $CONFIGURATION"
OUTPUT_DIR="./Products/"
# Simulator xcarchive (arm64 + x86_64)
xcodebuild archive \
ONLY_ACTIVE_ARCH=NO \
-scheme ${SCHEME_NAME} \
-project "${SCHEME_NAME}.xcodeproj" \
-archivePath ${SIMULATOR_ARCHIVE_PATH} \
-sdk iphonesimulator \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
SKIP_INSTALL=NO
# Device xcarchive (arm64)
xcodebuild archive \
-scheme ${SCHEME_NAME} \
-project "${SCHEME_NAME}.xcodeproj" \
-archivePath ${DEVICE_ARCHIVE_PATH} \
-sdk iphoneos \
BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
SKIP_INSTALL=NO
# Clean-up any existing instance of this xcframework from the Products directory
rm -rf "${OUTPUT_DIR}${SCHEME_NAME}.xcframework"
# Create final xcframework
xcodebuild -create-xcframework \
-framework ${DEVICE_ARCHIVE_PATH}/Products/Library/Frameworks/${FRAMEWORK_NAME}.framework \
-framework ${SIMULATOR_ARCHIVE_PATH}/Products/Library/Frameworks/${FRAMEWORK_NAME}.framework \
-output ${BUILD_DIR}/${FRAMEWORK_NAME}.xcframework
ERROR THAT I AM GETTING:
2023-11-20 23:44:06.736 xcodebuild[8267:239962] Writing error result bundle to /var/folders/ps/r75vk_f95tl2wh16jj2syv7c0000gr/T/ResultBundle_2023-20-11_23-44-0006.xcresult
xcodebuild: error: Unknown build action '.xcodeproj'.
error: the path does not point to a valid framework: /Users/coder/Library/Developer/Xcode/DerivedData/CoderSDK-cjavkiibuxlwhgftpsbjmlkavwpx/Build/Products/Debug/-iphoneos.xcarchive/Products/Library/Frameworks/.framework
The archive that is getting generated does not have .framework in it. I also tried using the -library parameter in the xcodebuild -create-xcframework command but that did not help either.
Can anyone please help me understand what is the issue here?
I had a similar problem. In my case the problem was, when searching the .xcarchive file I noticed that the .framework file was not in
but in
You can either change this in your script for it to find your .framework file or change it in Xcode under Build Settings -> Installation Directory