Framework
创建FrameWork

配置Framework
- Build Settings >> Dead Code Stripping >> 设置为NO
- Build Settings >> Strip Debug Symbol During Copy >> 全部设置为NO
- Build Settings >> Strip Style >> 设置为Non-Global Symbols
- Build Settings >> Link With Standard Libraries >> 设置为 NO
- Build Settings >> Mach-O Type >> Static Library
- 对于Mach-O Type:选择 Static Library 打包得到的是静态库
添加Aggregate


添加编译脚本

···
更新后的代码
FMK_NAME=${PROJECT_NAME}
INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework
WRK_DIR=build
DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.framework
SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build
#Xcode10此次clean会把当前目录删除然后,重新编译生成新的(即上一步真机生成)。
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator
#clean build
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi
mkdir -p "${INSTALL_DIR}"
cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"
lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}"
rm -r "${WRK_DIR}"
open "${SRCROOT}/Products/"
编译

编译成功后会自动跳出一个finder,保存这个.framework,这就是我们需要的framework。

使用FrameWork
如果是动态库:需要单独将framework嵌入到ipa安装包中,因为动态库的特点就是运行时加载,所以app的可执行程序中并不会链接其使用的动态库,需要将动态库和可执行程序同时放在安装包中:

此工程编译打包出来的app文件中,如下图所示,会增加一个Frameworks文件夹,里面存放的正式嵌入的动态库:

另外
如果Frmawork文件包含category,那么引用该动态库的文件应该设置
other linker flakes 为-all_load
网友评论