Skip to content

Instantly share code, notes, and snippets.

@wanyakun
Created May 8, 2017 06:29
Show Gist options
  • Save wanyakun/da8ccc4dbab8fcc57eca183d416f83fc to your computer and use it in GitHub Desktop.
Save wanyakun/da8ccc4dbab8fcc57eca183d416f83fc to your computer and use it in GitHub Desktop.
iOS build dynamic framework for cocoapods development. please put this shell file into library root path. Then run the BuildFramework.sh in terminal.
#当前目录
current_path=$(pwd)
#workspace绝对路径
workspace_path=$(pwd)/Example
#workspace
build_workspace=$(echo $(basename $workspace_path/*.xcworkspace))
#target 和workspace同名
build_target=$(echo $build_workspace | cut -d \. -f 1)
#删除旧的framework
framework=${current_path}/${build_target}.framework
if [[ -d "$framework" ]]; then
rm -rf ${framework}
fi
#Build路径
build_path=$(pwd)/build
#编译configuration,默认为Release
build_config=Release
#project
build_project=Pods.xcodeproj
#project_path
project_path=$(pwd)/Example/Pods/
cd $project_path
#build release device framework and release simulator framework
xcodebuild -project $build_project -target $build_target -configuration ${build_config} -sdk iphoneos BUILD_DIR="${build_path}" BUILD_ROOT="${build_path}" ONLY_ACTIVE_ARCH=NO clean build
xcodebuild -project $build_project -target $build_target -configuration ${build_config} -sdk iphonesimulator BUILD_DIR="${build_path}" BUILD_ROOT="${build_path}" ONLY_ACTIVE_ARCH=NO clean build
#将framework复制到项目根目录
cp -R "${build_path}/${build_config}-iphoneos/${build_target}/${build_target}.framework" "${current_path}/"
#合并真机和模拟器二进制文件
lipo -create -output "${current_path}/${build_target}.framework/${build_target}" "${build_path}/${build_config}-iphonesimulator/${build_target}/${build_target}.framework/${build_target}" "${build_path}/${build_config}-iphoneos/${build_target}/${build_target}.framework/${build_target}"
#清理build文件
rm -rf ${build_path}
rm -rf ${workspace_path}/build
#打开项目根目录文件夹
open "${current_path}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment