#!/bin/bash
#$1表示第一個(gè)參數(shù)
PROJECTPATH="$1"
build_configuration="Release"
# 是否編譯工作空間 (例:若是用Cocopods管理的.xcworkspace項(xiàng)目,賦值true;用Xcode默認(rèn)創(chuàng)建的.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"
# 指定輸出文件目錄不存在則創(chuàng)建
if [ -d "$export_path" ] ; then
echo $export_path
else
mkdir -pv $export_path
fi
# 判斷編譯的項(xiàng)目類型是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
#如果加上 預(yù)制描述文件
#xcodebuild \
#-scheme "${SCHEME_NAME}" \
#-sdk "${TARGET_SDK}" \
#-archivePath "${PROJECT_BUILDDIR}/${SCHEME_NAME}.xcarchive" \
#-configuration Release \
#PROVISIONING_PROFILE="${PROVISIONING_PROFILE}" \
#archive
fi
#? 檢查是否構(gòu)建成功
#? xcarchive 實(shí)際是一個(gè)文件夾不是一個(gè)文件所以使用 -d 判斷
if [ -d "$export_archive_path" ] ; then
echo "項(xiàng)目構(gòu)建成功 ?? ?? ?? "
else
echo "項(xiàng)目構(gòu)建失敗 ?? ?? ??"
exit 1
fi
echo "*************************? 開始導(dǎo)出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
## 輸出打包總用時(shí)
echo "打包總用時(shí): ${SECONDS}s "
open -R "$export_ipa_path"