BuildPhases->New Run Script Phases -> 添加脚本如下:
#这个是声明生成的framework的名字,保持工程名字一样
FMK_NAME=${PROJECT_NAME}
INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework
#创建目录
if [ "${ACTION}" = "build" ]
then
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi
mkdir -p "${INSTALL_DIR}"
#合并模拟器真机framework
DEVICE_DIR=${BUILD_ROOT}/${CONFIGURATION}-iphoneos/${FMK_NAME}.framework
SIMULATOR_DIR=${BUILD_ROOT}/${CONFIGURATION}-iphonesimulator/${FMK_NAME}.framework
cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"
cp -R "${SIMULATOR_DIR}/Modules/" "${INSTALL_DIR}/Modules"
rm "${INSTALL_DIR}/${FMK_NAME}"
lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}"
#目录
open "${SRCROOT}/Products"
fi
制作framework注意事项:
1.xcode->Edit Schema->Run->Build Configuration 改为Release
2.Build Settings -> Build Active Architecture Only 改为NO
3. Build Settings -> valid Architectures 支持 arm64 arm64e arm7 armv7s
4.general->Deployment info 为 target 支持到自己想要的版本,例如ios 8.0
5.Build Settings -> 搜索mach -> Mach-O type 改为static Library
6.如果库文件有swift ,Build Settings -> 搜索swift -> 修改swift相应的版本,最好是最新版
7.Build Phases -> Headers ->public 把需要暴露的文件(.h 或者 .swift文件 )拖到此处
8.由于 iOS 编译的特殊性,为了方便开发者在模拟器调试,很多 SDK 将i386、x86_64、armv7、arm64几个平台都合并到了一起。在开发阶段都没有问题,但生产编译上传到 App Store 时,需要将i386和x86_64两个平台的库删除,否则无法正常提交审核。
9.OC 代码,通过自定义framework,在调用的时候,里面的类扩展方法不能调用,解决方法:
build settings中的Other Linker Flags添加-Objc选项。这个选项会促使链接器加载库中所有定义了Class和Category的文件。但这些额外的代码会使目标文件变大。但在64位和iOS应用程序中,linker有一个bug,这个bug会导致objc选项无效,无法从静态库中加载只定义了Category的文件 ,这就需要添加-all_load或-force_load选项。
https://blog.csdn.net/qq_28865297/article/details/78227537
项目工程 中BuildPhases->New Run Script Phases -> 添加脚本如下:
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"
EXTRACTED_ARCHS=()
for ARCH in $ARCHS
do
echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
done
echo "Merging extracted architectures: ${ARCHS}"
lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
rm "${EXTRACTED_ARCHS[@]}"
echo "Replacing original executable with thinned version"
rm "$FRAMEWORK_EXECUTABLE_PATH"
mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"
done
去除 x86_64, i386 脚本转自地址:
https://blog.csdn.net/weixin_33852020/article/details/87545284