iOS SDK Development - use automated build scripts quickly output SDK

Often encounter the situation needs to be packaged in the development sdk, sdk if it is more than natural development is to build automated packaging platform, using automated packaging more convenient and efficient platform, but developed sdk single package or configuration script is more convenient and efficient, this article describes two species are packaged under the common sdk development mode.

1. Use the library cocoapods created

  1. Use pod lib create MyLibraryCreate a library

  2. In this installation gem install cocoapods-packager

  3. Run pod package MyLibrary.podspecoutput sdk

    Exception Handling:

    1. If only local development, the library did not submit to the repo, you need to MyLibrary.podspec the s.sourcepoint to the local library path

    2. The need to play a dynamic library, static library, framework run pod package —helpview command

2. general way, contains sdk target Xcode project

Script principles and instructions are detailed in the notes shell script

Use:

  1. The first: direct run shell scripts

    The script file and project file at the same path, the command line to open the directory script execution sh shellName.sh

  2. Second: Create a new Aggregate target in the current project, add a new Run Script Phase Build Phases in the target's, the target will be run separately to produce good sdk

  1. Third: Adding a new Run Script Phase in the Build Phases target of years, it will run the script when you run the tartget, generate sdk

    Adding script we created in the run script in the path of the newly added "$ {SRCROOT} /path/shellName.sh"

#!/bin/sh

# workspace 工程名,如果是单 target 项目则不需要
PROJECT_NAME='XXX_project'
# target 名
TARGET_NAME="XXX_target"
# 工程文件所在的根目录
SRCROOT='.'

# Sets the target folders and the final framework product.
FMK_NAME='sdk_name'

# 最终 sdk 输出的文件路径
# 在工程文件所在的根目录创建 sdk 输出路径,如果是 framework 形式则为 .framework
INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework
# 在工程文件所在的根目录创建 sdk 输出路径,如果是 static lib 形式则为 .a
# INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.a


# sdk 编译过程的输出文件路径
WRK_DIR=./build
# framework 形式真机架构输出文件路径
DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}/${FMK_NAME}.framework
# static lib 形式真机架构输出文件路径
# DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.a
# framework 形式模拟器架构输出文件路径
SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}/${FMK_NAME}.framework
# static lib 形式模拟器架构输出文件路径
# SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.a

# -configuration ${CONFIGURATION}
# 清理编译生成真机和模拟器架构的 sdk

# 单 target 项目
# xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build
# xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean build

# 包含 workspace 的项目
xcodebuild -configuration Release -workspace "${PROJECT_NAME}.xcworkspace" -scheme "${TARGET_NAME}" -sdk iphoneos clean  build SYMROOT="../${WRK_DIR}"
xcodebuild -configuration Release -workspace "${PROJECT_NAME}.xcworkspace" -scheme "${TARGET_NAME}" -sdk iphonesimulator build SYMROOT="../${WRK_DIR}"

# 清理之前生成的 sdk
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi

mkdir -p ${SRCROOT}/Products

cp -LR "${DEVICE_DIR}" "${INSTALL_DIR}"

echo "DEVICE_DIR: ${DEVICE_DIR}"
echo "INSTALL_DIR: ${INSTALL_DIR}"

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

rm -r "${WRK_DIR}"

if [ -d "${INSTALL_DIR}/_CodeSignature" ]
then
rm -rf "${INSTALL_DIR}/_CodeSignature"
fi

if [ -f "${INSTALL_DIR}/Info.plist" ]
then
rm "${INSTALL_DIR}/Info.plist"
fi

复制代码

Guess you like

Origin blog.csdn.net/weixin_33978044/article/details/91369281
Recommended