Packaging is often needed when developing SDK. If the SDK is developed by many people, it is natural to build an automatic packaging platform, which is convenient and quick to use. However, it is convenient and quick to configure packaging script for SDK developed by one person.
1. Use the libraries created by Cocoapods
-
Create the library using pod Lib create MyLibrary
-
Install gem Install Cocoapods-Packager on your PC
-
Run pod Package myLibrary. podSpec to output the SDK
Exception handling:
1. If you are only developing locally without committing the library to the REPO, you need to point s.ource in myLibrary.podSpec to the local library path
2. Run pod Package -help to view related commands
2. General mode, including Xcode project with SDK target
The principle and usage of the script are described in details in the comments of shell scripts
Usage:
-
First: Run the shell script directly
The script file is in the same directory as the project file. Open the script directory and run sh shellname.sh
-
Second, create a new Aggregate Target under the current project, add a new Run Script Phase to the Build Phases of the target, and Run the target alone to produce the SDK
-
Third, add a new Run Script Phase to target’s Build Phases, which will Run when the tartget is executed to generate the SDK
Add “${SRCROOT}/path/ shellname.sh “to the newly added run script.
#! /bin/sh
#Workspace project name, not required if it is a single target project
PROJECT_NAME='XXX_project'
#The target of
TARGET_NAME="XXX_target"
#Root directory of the project file
SRCROOT='.'
# Sets the target folders and the final framework product.
FMK_NAME='sdk_name'
#Path to the final SDK output file
#Create the SDK output path in the root directory of the project file, or.framework if it is in framework format
INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework
#Create the SDK output path in the root directory of the project file, or.a if it is static lib
# INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.a
#Path to the SDK compilation output file
WRK_DIR=./build
#Framework output file path of the real machine architecture
DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}/${FMK_NAME}.framework
#Static lib path to the output file of the real machine architecture
# DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.a
#Framework emulator architecture output file path
SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}/${FMK_NAME}.framework
#Path to the output file of the static lib simulator architecture
# SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.a
# -configuration ${CONFIGURATION}
#Clean up the SDK that builds the real machine and simulator architecture
#Single target project
# xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build
# xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean build
#Projects that contain workspacexcodebuild -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}"
#Clean up the PREVIOUSLY generated 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
Copy the code