#!/bin/bash
#$1表示第一个参数
PROJECTPATH="$1"
build_configuration="Release"
# 是否编译工作空间 (例:若是用Cocopods管理的.xcworkspace项目,赋值true;用Xcode默认创建的.xcodeproj,赋值false)
is_workspace=$"false"
# 指定要打包编译的方式 : Release,Debug...
build_configuration="Release"
projectDirectory=`echo ${PROJECTPATH%/*}`
projectFile=`echo ${PROJECTPATH##*/}`
scheme_name=`echo ${projectFile%.*}`
echo $projectDirectory
cd "$projectDirectory"
info_plist_path="${projectDirectory}/${scheme_name}/Info.plist"
EXPORT_PLIST="${projectDirectory}/${scheme_name}/EXPORT_PLIST.plist"
bundle_version=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" $info_plist_path`
bundle_build_version=`/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" $info_plist_path`
bundle_identifier=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $info_plist_path`
# 删除旧.xcarchive文件
rm -rf ~/Desktop/$scheme_name-IPA/$scheme_name.xcarchive
# 指定输出ipa路径
export_path=~/Desktop/$scheme_name-IPA
# 指定输出归档文件地址
export_archive_path="$export_path/$scheme_name.xcarchive"
# 指定输出ipa地址# 指定输出ipa名称 : scheme_name + bundle_version
export_ipa_path="$export_path"
ipa_name="$scheme_name-v$bundle_version"
# 指定输出文件目录不存在则创建
if [ -d "$export_path" ] ; then
echo $export_path
else
mkdir -pv $export_path
fi
# 判断编译的项目类型是workspace还是project
if $is_workspace ; then
# 编译前清理工程
xcodebuild clean -workspace ${PROJECTPATH}.xcworkspace \
-scheme ${scheme_name} \
-configuration ${build_configuration}
xcodebuild archive -workspace ${PROJECTPATH}.xcworkspace \
-scheme ${scheme_name} \
-configuration ${build_configuration} \
-archivePath ${export_archive_path}
else
# 编译前清理工程
echo ${PROJECTPATH}
xcodebuild clean -project ${PROJECTPATH} \
-scheme ${scheme_name} \
-configuration ${build_configuration}
xcodebuild \
-scheme "${scheme_name}" \
-archivePath ${export_archive_path} \
-configuration ${build_configuration} \
archive
#如果加上 预制描述文件
#xcodebuild \
#-scheme "${SCHEME_NAME}" \
#-sdk "${TARGET_SDK}" \
#-archivePath "${PROJECT_BUILDDIR}/${SCHEME_NAME}.xcarchive" \
#-configuration Release \
#PROVISIONING_PROFILE="${PROVISIONING_PROFILE}" \
#archive
fi
# 检查是否构建成功
# xcarchive 实际是一个文件夹不是一个文件所以使用 -d 判断
if [ -d "$export_archive_path" ] ; then
echo "项目构建成功 🚀 🚀 🚀 "
else
echo "项目构建失败 😢 😢 😢"
exit 1
fi
echo "************************* 开始导出ipa文件 ************************* "
xcodebuild \
-exportArchive \
-archivePath ${export_archive_path} \
-exportOptionsPlist "${EXPORT_PLIST}" \
-exportPath ${export_ipa_path}
## 修改ipa文件名称
mv $export_ipa_path/$scheme_name.ipa $export_ipa_path/$ipa_name.ipa
## 输出打包总用时
echo "打包总用时: ${SECONDS}s "
open -R "$export_ipa_path"
网友评论