1.创建framework
1). framework的基本介绍以及创建参考如下,此处不再赘述
http://www.jianshu.com/p/de006feae864(注:接下来的介绍是基于已知该文章中的基本操作)
2). 工程中引入pod需要管理的第三方库,此处可众里寻他千百度,也可翻墙google下(你开心就好)
3). 创建基于pod管理的工作组,如下:
2.编译 真机 / 模拟器 的 包
1).编译并查看相关文件
对工程进行编译(command + B)
, 找到project->products->选中EKWBaseNetWorkRequest.framework ->Show In Finder
, 如下图:
查看 生成的framework, 可以发现,无论是真机还是模拟器文件, pod中使用的Alamofire并没有打包进入EKWBaseNetWorkRequest.framework中, 而是单独包含在一个文件中, 所以此处的合包和使用必定不平凡
使用终端合包的 具体操作参考文章开头 提到的文章, 此处直接进入脚本编译合包
3.使用脚本编译
1). 添加target的 Aggregate
以及脚本文件
方法参考文章开头 提到的文章
2). 注入脚本
与基于project的操作不同之处在于:
1.基于workspace的编译, 而非project(后缀为xcworkspace)
2.需要分别合并EKWBaseNetWorkRequest.framework 以及Alamofire.framework.
注: Alamofire.framework 需要重新创建文件夹(UNIVERSAL_Alamofire_OUTPUTFOLDER="${SRCROOT}/${PROJECT_NAME}_Products/Alamofire/"
), 否则复制过程中, 我们操作的是framework下的文件, 会被EKWBaseNetWorkRequest.framework下的文件覆盖
用到的脚本如下:
#!/bin/sh
UNIVERSAL_OUTPUTFOLDER="${SRCROOT}/${PROJECT_NAME}_Products/"
UNIVERSAL_Alamofire_OUTPUTFOLDER="${SRCROOT}/${PROJECT_NAME}_Products/Alamofire/"
WORKSPACE_NAME=${PROJECT_NAME}.xcworkspace
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
mkdir -p "${UNIVERSAL_Alamofire_OUTPUTFOLDER}"
rm -rf "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework"
rm -rf "${UNIVERSAL_Alamofire_OUTPUTFOLDER}/Alamofire.framework"
# Step 1. Build Device and Simulator versions
xcodebuild -workspace "${WORKSPACE_NAME}" -scheme "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphoneos ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -workspace "${WORKSPACE_NAME}" -scheme "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
# Step 2. Copy the framework structure (from iphoneos build) to the universal folder
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework" "${UNIVERSAL_OUTPUTFOLDER}"
#拷贝Alamofireframework到univer目录
cp -R "${BUILD_DIR}/${CONFIGURATION}-iphoneos/Alamofire/Alamofire.framework" "${UNIVERSAL_Alamofire_OUTPUTFOLDER}"
# Step 3. Copy Swift modules from iphonesimulator build (if it exists) to the copied framework directory
SIMULATOR_SWIFT_MODULES_DIR="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule/."
if [ -d "${SIMULATOR_SWIFT_MODULES_DIR}" ]; then
cp -R "${SIMULATOR_SWIFT_MODULES_DIR}" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/Modules/${PROJECT_NAME}.swiftmodule"
fi
# Step 4. Create universal binary file using lipo and place the combined executable in the copied framework directory
lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.framework/${PROJECT_NAME}" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.framework/${PROJECT_NAME}"
#合并Alamofireframework,输出最终的framework到build目录
lipo -create -output "${UNIVERSAL_Alamofire_OUTPUTFOLDER}/Alamofire.framework/Alamofire" "${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/Alamofire/Alamofire.framework/Alamofire" "${BUILD_DIR}/${CONFIGURATION}-iphoneos/Alamofire/Alamofire.framework/Alamofire"
#删除编译之后生成的无关的配置文件
dir_path="${UNIVERSAL_OUTPUTFOLDER}/${TARGET_NAME}.framework/"
for file in ls $dir_path
do
if [[ ${file} =~ ".xcconfig" ]]
then
rm -f "${dir_path}/${file}"
fi
done
#打开合并后的文件夹
open "${UNIVERSAL_OUTPUTFOLDER}"
3). 生成的framework 如下:
参考链接:
http://www.hangge.com/blog/cache/detail_1426.html
http://www.jianshu.com/p/68c0f40a3387
以上仅是个人使用总结,欢迎批评指正补充~~~~~~~