iOS打包的流程:
配置(编译器确定当前系统环境)-> 确定标准库和头文件的位置->确定依赖关系->头文件预编译(precompilation)->预处理(preprocessing)->编译(compilation)->连接(Linking)->打包
使用教程
将ipa_build这个文件夹移到和.xcodeproj或.xcworkspace同一级目录
打开build_debug或者build_release文件,替换profile_name字段,替换为你要打包项目的profile name
打开你的终端:
$ cd 脚本所在的目录
$ chmod 777 build_debug.sh (仅第一次的时候需要)
$ ./build_debug.sh
查看你的桌面即可以查看导出的IPA包。
ipa_build/build_debug.sh:
#!/bin/sh
#--------------------------------------------
# 功能:实现Debug版本的打包
# 作者:Panda
# 使用教程: 1. cd 脚本所在的目录
# 2. chmod 777 build_debug.sh (仅第一次的时候需要)
# 3. ./build_debug.sh
# 创建日期:2016/02/22
#--------------------------------------------
# 替换你要打包项目的 profile name
profile_name='jeikerxiao Profile Test'
echo "======Debug Profile name:${profile_name}======"
# 获取工程根目录
xCodeBuild_GetDocumentDirPath(){
project_Path=$(pwd)
echo ${project_Path}
}
cd ..
# 获取ipa文件导出路径
build_outputPath(){
#cd ..
scheme=$(ls | grep xcodeproj | awk -F.xcodeproj '{print $1}')
cd ~/Desktop
SYSTEM_TIME=`date '+%Y-%m-%d-%T'`
outputPath=$(pwd)/${scheme}_${SYSTEM_TIME}
mkdir ${outputPath}
#cd ${projectPath}
echo ${outputPath}
}
buildExportPath=$(build_outputPath)
echo "======输出路径:${buildExportPath}======"
# 打包类型
build_Mode='Debug'
# 工程名称
project_name=$(ls | grep xcodeproj | awk -F.xcodeproj '{print $1}')
echo "======工程名字:${project_name}======"
# 获取工程绝对路径
project_path=$(xCodeBuild_GetDocumentDirPath)
echo "======工程绝对路径:${project_path}======"
#echo ${project_path}
# 获取xcworkSpace的路径
workspacePath=${project_path}/${project_name}.xcworkspace
echo "======workspacePath路径:${workspacePath}======"
# build文件夹路径
build_path=${project_path}/build
# 工程配置文件路径
project_name=$(ls | grep xcodeproj | awk -F.xcodeproj '{print $1}')
project_infoplist_path=${project_path}/${project_name}/${project_name}-Info.plist
# 取版本号
bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" ${project_infoplist_path})
# 取build值
bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" ${project_infoplist_path})
# 取bundle Identifier前缀
bundlePrefix=$(/usr/libexec/PlistBuddy -c "print CFBundleIdentifier" `find . -name "*-Info.plist"` | awk -F$ '{print $1}')
# 进入工程路径下
cd ${project_path}
echo 开始清理工程~
# 删除bulid目录
if [ -d ${build_path} ];
then
rm -rf ${build_path}
echo 清理build文件成功
fi
# 清理工程
xcodebuild clean -configuration ${build_Mode} || exit
if [ -d ${workspacePath} ];
then
echo 当前工程使用cocoapods
# 编译
xctool -workspace ${project_path}/${project_name}.xcworkspace -scheme ${project_name} archive -archivePath ${project_path}/build/Debug-iphoneos/${project_name}_Debug.xcarchive -configuration ${build_Mode} || exit
# 打包
xcodebuild -exportArchive -archivePath ${project_path}/build/Debug-iphoneos/${project_name}_Debug.xcarchive -exportPath ${buildExportPath}/debug.ipa -exportFormat ipa -exportProvisioningProfile "${profile_name}" || exit
else
echo 当前工程没有使用cocoapods
# 编译
xctool -project ${project_path}/${project_name}.xcodeproj -scheme ${project_name} archive -archivePath ${project_path}/build/Debug-iphoneos/${project_name}_Debug.xcarchive -configuration ${build_Mode} || exit
# 打包
xcodebuild -exportArchive -archivePath ${project_path}/build/Debug-iphoneos/${project_name}_Debug.xcarchive -exportPath ${buildExportPath}/debug.ipa -exportFormat ipa \
-exportProvisioningProfile "${profile_name}" || exit
fi
if [ -d ./ipa-build ];then
rm -rf ipa-build
fi
if [ -d ./build/Debug-iphoneos ];then
rm -rf Debug-iphoneos
fi
ipa_build/build_release.sh:
#!/bin/sh
#--------------------------------------------
# 功能:实现Release版本的打包
# 作者:Panda
# 使用教程: 1. cd 脚本所在的目录
# 2. chmod 777 build_release.sh (仅第一次的时候需要)
# 3. ./build_release.sh
# 注:这边生成的release.ipa 相当于发布到iTunes connect上的IPA,证书须为对应的distribution证书
# 创建日期:2016/02/22
#--------------------------------------------
profile_name='jeikerxiao Profile Test'
echo "======Release Profile name:${profile_name}======"
# 获取工程根目录
xCodeBuild_GetDocumentDirPath(){
project_Path=$(pwd)
echo ${project_Path}
}
cd ..
# 获取ipa文件导出路径
build_outputPath(){
#cd ..
scheme=$(ls | grep xcodeproj | awk -F.xcodeproj '{print $1}')
cd ~/Desktop
SYSTEM_TIME=`date '+%Y-%m-%d-%T'`
outputPath=$(pwd)/${scheme}_${SYSTEM_TIME}
mkdir ${outputPath}
#cd ${projectPath}
echo ${outputPath}
}
buildExportPath=$(build_outputPath)
echo "======输出路径:${buildExportPath}======"
build_Mode='Release'
# 工程名称
project_name=$(ls | grep xcodeproj | awk -F.xcodeproj '{print $1}')
# 获取工程绝对路径
project_path=$(xCodeBuild_GetDocumentDirPath)
# 获取xcworkSpace的路径
workspacePath=${project_path}/${project_name}.xcworkspace
# build文件夹路径
build_path=${project_path}/build
# 工程配置文件路径
project_name=$(ls | grep xcodeproj | awk -F.xcodeproj '{print $1}')
project_infoplist_path=${project_path}/${project_name}/${project_name}-Info.plist
# 取版本号
bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" ${project_infoplist_path})
# 取build值
bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" ${project_infoplist_path})
# 取bundle Identifier前缀
bundlePrefix=$(/usr/libexec/PlistBuddy -c "print CFBundleIdentifier" `find . -name "*-Info.plist"` | awk -F$ '{print $1}')
# 进入工程路径下
cd $project_path
echo 开始清理工程~
# 删除bulid目录
if [ -d ${build_path} ];
then
rm -rf ${build_path}
echo 清理build文件成功
fi
# 清理工程
xcodebuild clean -configuration ${build_Mode} || exit
if [ -d ${workspacePath} ];
then
echo 当前工程使用cocoapods
#xcodebuild -configuration ${build_Mode} -workspace ${project_path}/${project_name}.xcworkspace \
#-scheme ${project_name} \
#ONLY_ACTIVE_ARCH=NO \
#TARGETED_DEVICE_FAMILY=1 \
#DEPLOYMENT_LOCATION=YES CONFIGURATION_BUILD_DIR=${project_path}/build/Release-iphoneos || exit
# 编译
xctool -workspace ${project_path}/${project_name}.xcworkspace -scheme ${project_name} archive -archivePath ${project_path}/build/Release-iphoneos/${project_name}_Release.xcarchive -configuration ${build_Mode} || exit
# 打包
xcodebuild -exportArchive -archivePath ${project_path}/build/Release-iphoneos/${project_name}_Release.xcarchive -exportPath ${buildExportPath}/release.ipa -exportFormat ipa \
-exportProvisioningProfile "${buildExportPath}" || exit
else
echo 当前工程没有使用cocoapods
#xcodebuild -configuration ${build_Mode} -project ${project_path}/${project_name}.xcodeproj \
#-scheme ${project_name} \
#ONLY_ACTIVE_ARCH=NO \
#TARGETED_DEVICE_FAMILY=1 \
#DEPLOYMENT_LOCATION=YES CONFIGURATION_BUILD_DIR=${project_path}/build/Release-iphoneos || exit
# 编译
xctool -workspace ${project_path}/${project_name}.xcworkspace -scheme ${project_name} archive -archivePath ${project_path}/build/Release-iphoneos/${project_name}_Release.xcarchive -configuration ${build_Mode} || exit
# 打包
xcodebuild -exportArchive -archivePath ${project_path}/build/Release-iphoneos/${project_name}_Release.xcarchive -exportPath ${buildExportPath}/release.ipa -exportFormat ipa \
-exportProvisioningProfile "${buildExportPath}" || exit
fi
# 将归档文件移动到输出目录下
mv -v ${project_path}/build/Release-iphoneos/${project_name}_Release.xcarchive ${buildExportPath}/Release.xcarchive
if [ -d ./ipa-build ];then
rm -rf ipa-build
fi
if [ -d ./build/Debug-iphoneos ];then
rm -rf Debug-iphoneos
fi