制作SDK时的坑和经验

一、坑

1、分类
虽然分类使用方便,但是集成到SDK中,会经常出现找不到方法的问题。
解决方案:修改link flags(推荐) ;用用工具类实现分类的功能。
2、NSClassFromClass()
如果other link flags配置中没有-Objc_all,即没有全部加载,直接崩溃。但是-Objc_all会引入其他编译错误,记得是在官方网站找到解决方案,添加$(OTHER_LDFLAGS)

制作SDK时的坑和经验_第1张图片
image.png

二、经验:

1、使用脚本打出SDK:
模拟器和真机的SDK,如果每次编译然后手动合并很麻烦,用脚本可以省去许多容易出错的问题。
以下为收集总结的脚本,TKOpen为项目名,或者直接写成${PROJECT_NAME}。

# Sets the target folders and the final framework product.
FMK_NAME=TKOpen
# Install dir will be the final output to the framework.
# The following line create it in the root folder of the current project.
INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework
# Working dir will be deleted after the framework creation.
WRK_DIR=build
DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.framework
SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework
# Building both architectures.
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator
# Cleaning the oldest.
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi
# Creates and renews the final product folder.
mkdir -p "${INSTALL_DIR}"
# Copies the headers and resources files to the final product folder.
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}"
rm -r "${WRK_DIR}"

open ${INSTALL_DIR}

2、可以把一个项目搞成多个Target,这样无论是把App不同模块的制作成SDK,还是对试验,都很方便。
制作成不同的SDK:可以在代码中判断宏的定义,进行预编译,生成不同的SDK。如图所示,在Preprocessor Macros中进行配置。

制作SDK时的坑和经验_第2张图片
image.png

3、引用项目外的文件
有时候为了减少给出去的SDK的体积大小,需要把demo中的SDK删除,并引用项目外中libs中的SDK。
如图,修改Framework Search Path、Header search Path、Library Search Path,如图:

制作SDK时的坑和经验_第3张图片
image.png

${PROJECT_DIR}/../libs 是获取项目最外层目录同级目录的相对路径。

你可能感兴趣的:(制作SDK时的坑和经验)