Swift制作打包framework

新建framework项目

Swift制作打包framework_第1张图片

 Swift制作打包framework_第2张图片

设置生成fat包,包括模拟器x86_64和arm64

Buliding Settings -> Architectures -> Build Active Architecture Only 设置为NO

设置打包环境,选择release

edit Scheme -> run -> Build configuration 设置为 Release

Swift制作打包framework_第3张图片

设置静态库

 Buliding Settings -> Linking -> Dead Code Stripping 设置为NO

 Buliding Settings -> Linking -> Mach-O Type 设置为Static Library

Swift制作打包framework_第4张图片

创建打包合并framework脚本

Swift制作打包framework_第5张图片

Swift制作打包framework_第6张图片

Swift制作打包framework_第7张图片

添加打包+合成脚本代码:

# Install dir will be the final output to the framework.
# The following line create it in the root folder of the current project.
FMK_NAME=${PROJECT_NAME}
INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework

# Working dir will be deleted after the framework creation.
WRK_DIR=build
DEVICE_DIR=${WRK_DIR}/Build/Products/Release-iphoneos/${FMK_NAME}.framework
SIMULATOR_DIR=${WRK_DIR}/Build/Products/Release-iphonesimulator/${FMK_NAME}.framework

# -configuration ${CONFIGURATION}
# Clean and Building both architectures.
xcodebuild -project ${FMK_NAME}.xcodeproj -scheme ${FMK_NAME}  -configuration Release -derivedDataPath ${WRK_DIR} clean

xcodebuild -project ${FMK_NAME}.xcodeproj -scheme ${FMK_NAME} -configuration Release -derivedDataPath ${WRK_DIR} -sdk iphoneos -arch arm64  clean build
# simulator
xcodebuild -project ${FMK_NAME}.xcodeproj -scheme ${FMK_NAME} -configuration Release -derivedDataPath ${WRK_DIR} -sdk iphonesimulator -arch x86_64 build

# Cleaning the oldest.
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi


mkdir -p "${INSTALL_DIR}"

cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"

# Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product.
lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}"

cp -R "${SIMULATOR_DIR}/Modules/${FMK_NAME}.swiftmodule" "${INSTALL_DIR}/Modules/"

#rm -r "${WRK_DIR}"

open "${SRCROOT}/Products/"

运行脚本,生成的framework会在项目根目录的Products文件夹下。

你可能感兴趣的:(iOS,swift,ios)