前面做了自動打包并上傳蒲公英的腳本送爸,
這次做了一些處理铛嘱,讓手機(jī)上可以同時安裝原版和測試版的
做完以后可以:開發(fā)過程一鍵自動打包ipa包上傳到蒲公英,測試人員可以安裝一個appstore版本安裝一個測試版袭厂,上傳appstore手動打包上傳
后面在代碼里面配置一下Debug的IP測試環(huán)境墨吓,DevRelease的IP是UAT環(huán)境,然后release的IP自動改成正式環(huán)境的纹磺。這樣打包運行就不用管了
本來只有Debug和release的現(xiàn)在把release復(fù)制一份出來DevRelease帖烘,專門用來打包
先增加一個環(huán)境,我是復(fù)制的release橄杨,因為打包用release比較好
xcode14使用老項目出現(xiàn)顯示的名稱無法修改參考這個
https://juejin.cn/post/7197361396219772983
我這里處理是方案一修改成 $(INFOPLIST_KEY_CFBundleDisplayName)
在這個地方修改秘症,讓app顯示的可以區(qū)分。
也可以不同環(huán)境使用不同的圖標(biāo)式矫,在build settings里搜索asset catalog,然后找到 Asset Catalog App Icon Set Name 設(shè)置對應(yīng)icon的圖片名稱
直接跑使用Debug乡摹,包名是dev,DevRelease是打包成ipa的給別人安裝的使用Release但是包名也是dev采转,
Release就用來打包上傳appstore的包名沒有dev
完成以后重新執(zhí)行pod install聪廉,可以看到pod自動增加了新的環(huán)境
#!/usr/bin/env bash
echo "how to use."
echo "===================="
echo "默認(rèn)使用 DevRelease"
echo "./ipa.sh"
echo "===================="
echo "build for release"
echo "./ipa.sh --release"
echo "===================="
echo "參數(shù)1:release,debug,參數(shù)2:appStore,adHoc"
echo "./ipa.sh --release --app-store"
echo "===================="
sleep 1
#
#
#
#
#
#
# 使用方法:
# step1: 將該腳本放在工程的根目錄下(跟.xcworkspace文件or .xcodeproj文件同目錄)
# step2: 根據(jù)情況修改下面的參數(shù)
# step3: 打開終端,執(zhí)行腳本故慈。(輸入sh 板熊,然后將腳本文件拉到終端,會生成文件路徑察绷,然后enter就可)
# =============項目自定義部分(自定義好下列參數(shù)后再執(zhí)行該腳本)=================== #
# 是否編譯工作空間 (例:若是用Cocopods管理的.xcworkspace項目,賦值true;用Xcode默認(rèn)創(chuàng)建的.xcodeproj,賦值false)
echo $1 $2
configuration_type=$1
method_type=$2
if [ "$configuration_type" == "--release" ]; then
build_configuration="Release"
echo "==編譯Release=="
elif [ "$configuration_type" == "--Debug" ]; then
build_configuration="Debug"
echo "==編譯Debug=="
else
build_configuration="DevRelease"
echo "*****==編譯DebugDev=="
fi
if [ "$method_type" == "--app-store" ]; then
method="app-store"
echo "==打包app-store=="
elif [ "$method_type" == "--ad-hoc" ]; then
method="ad-hoc"
echo "==打包ad-hoc=="
else
method="development"
echo "*****==打包development=="
fi
# 1111--指定要打包編譯的方式 : Release,Debug干签。一般用Release。必填輸入第二個參數(shù)
#build_configuration="Release"
# 2222--method拆撼,打包的方式筒严。方式分別為 development, ad-hoc, app-store, enterprise 丹泉。必填
#method="development"
is_workspace="true"
# .xcworkspace的名字情萤,如果is_workspace為true鸭蛙,則必須填。否則可不填
workspace_name="Luxxxx"
# .xcodeproj的名字筋岛,如果is_workspace為false娶视,則必須填。否則可不填
project_name=""
# 指定項目的scheme名稱(也就是工程的target名稱)睁宰,必填
scheme_name="Luxxxx"
#compileBitcode選項沒有配置,默認(rèn)compileBitcode為YES,要設(shè)置成NO就可以了
compileBitcode="NO"
# 下面兩個參數(shù)只是在手動指定Pofile文件的時候用到肪获,如果使用Xcode自動管理Profile,直接留空就好
# (跟method對應(yīng)的)mobileprovision文件名,需要先雙擊安裝.mobileprovision文件.手動管理Profile時必填
mobileprovision_name=""
# 項目的bundleID柒傻,手動管理Profile時必填
bundle_identifier=""
# 蒲公英app key
api_key="xxx"
echo "--------------------腳本配置參數(shù)檢查--------------------"
echo "\0=====is_workspace=${is_workspace} "
echo "workspace_name=${workspace_name}"
echo "project_name=${project_name}"
echo "scheme_name=${scheme_name}"
echo "build_configuration=${build_configuration}"
echo "bundle_identifier=${bundle_identifier}"
echo "method=${method}"
echo "mobileprovision_name=${mobileprovision_name} \0====="
echo "--------------------xxx---------------------"
# =======================腳本的一些固定參數(shù)定義(無特殊情況不用修改)====================== #
# 獲取當(dāng)前腳本所在目錄
script_dir="$( cd "$( dirname "$0" )" && pwd )"
# 工程根目錄
project_dir=$script_dir
# 時間
DATE=`date '+%Y%m%d_%H%M%S'`
# 指定輸出導(dǎo)出文件夾路徑-寫到項目之外不然還要加入忽略白名單
#export_path="$project_dir/Package/$scheme_name-$DATE"
export_path="/Users/xxx電腦的user/Desktop/Package/$scheme_name-$DATE"
# 指定輸出歸檔文件路徑
export_archive_path="$export_path/$scheme_name.xcarchive"
# 指定輸出ipa文件夾路徑
export_ipa_path="$export_path"
# 指定輸出ipa名稱
#ipa_name="${scheme_name}_${DATE}"
ipa_name="Luxxxx"
# 指定導(dǎo)出ipa包需要用到的plist配置文件的路徑
export_options_plist_path="$project_dir/ExportOptions.plist"
echo "--------------------增加版本號-------------"
#獲取當(dāng)前版本號
get_build_version=`xcodebuild -showBuildSettings -target $scheme_name | grep CURRENT_PROJECT_VERSION | tr -d 'CURRENT_PROJECT_VERSION = '`
old_build_version=$get_build_version
echo "old_build_version = $old_build_version"
#版本號增加
agvtool new-version $(($old_build_version+1))
#輸出新版本號
#get_current_build_veresion=`xcodebuild -showBuildSettings -target $scheme_name | grep CURRENT_PROJECT_VERSION | tr -d 'CURRENT_PROJECT_VERSION = '`
#current_build_veresion=$get_current_build_veresion
#echo "current_build_veresion = $current_build_veresion"
echo "--------------------腳本固定參數(shù)檢查--------------------"
echo "\0=====;1mproject_dir=${project_dir}"
echo "DATE=${DATE}"
echo "export_path=${export_path}"
echo "export_archive_path=${export_archive_path}"
echo "export_ipa_path=${export_ipa_path}"
echo "export_options_plist_path=${export_options_plist_path}"
echo "ipa_name=${ipa_name} \0====="
# =======================自動打包部分(無特殊情況不用修改)====================== #
echo "------------------------------------------------------"
echo "\0=====開始構(gòu)建項目 \0====="
# 進(jìn)入項目工程目錄
cd ${project_dir}
# 指定輸出文件目錄不存在則創(chuàng)建
if [ -d "$export_path" ] ; then
echo $export_path
else
mkdir -pv $export_path
fi
# 判斷編譯的項目類型是workspace還是project
if $is_workspace ; then
# 編譯前清理工程
xcodebuild clean -workspace ${workspace_name}.xcworkspace \
-scheme ${scheme_name} \
-configuration ${build_configuration}
xcodebuild archive -workspace ${workspace_name}.xcworkspace \
-scheme ${scheme_name} \
-configuration ${build_configuration} \
-archivePath ${export_archive_path}
else
# 編譯前清理工程
xcodebuild clean -project ${project_name}.xcodeproj \
-scheme ${scheme_name} \
-configuration ${build_configuration}
xcodebuild archive -project ${project_name}.xcodeproj \
-scheme ${scheme_name} \
-configuration ${build_configuration} \
-archivePath ${export_archive_path}
fi
# 檢查是否構(gòu)建成功
# xcarchive 實際是一個文件夾不是一個文件所以使用 -d 判斷
if [ -d "$export_archive_path" ] ; then
echo "\0=====項目構(gòu)建成功 ?? ?? ?? \0====="
else
echo "\0=====項目構(gòu)建失敗 ?? ?? ?? \0====="
exit 1
fi
echo "------------------------------------------------------"
echo "\0====開始導(dǎo)出ipa文件 \0====="
# 檢查是否有dSYM文件
dSYM_path="$export_archive_path/dSYMs/$scheme_name.app.dSYM"
export_dSYM_path="$export_path/$scheme_name.app.dSYM"
if [ -d $dSYM_path ]; then
cp -r $dSYM_path $export_dSYM_path
else
echo "no dSYM file"
echo "dSYM_path=${dSYM_path}"
fi
# 先刪除export_options_plist文件
if [ -f "$export_options_plist_path" ] ; then
#echo "${export_options_plist_path}文件存在孝赫,進(jìn)行刪除"
rm -f $export_options_plist_path
fi
# 根據(jù)參數(shù)生成export_options_plist文件
/usr/libexec/PlistBuddy -c "Add :compileBitcode bool ${compileBitcode}" $export_options_plist_path
/usr/libexec/PlistBuddy -c "Add :method string ${method}" $export_options_plist_path
/usr/libexec/PlistBuddy -c "Add :provisioningProfiles:" $export_options_plist_path
/usr/libexec/PlistBuddy -c "Add :provisioningProfiles:${bundle_identifier} string ${mobileprovision_name}" $export_options_plist_path
xcodebuild -exportArchive \
-archivePath ${export_archive_path} \
-exportPath ${export_ipa_path} \
-exportOptionsPlist ${export_options_plist_path} \
-allowProvisioningUpdates
# 檢查ipa文件是否存在
if [ -f "$export_ipa_path/$scheme_name.ipa" ] ; then
echo "\0=====exportArchive ipa包成功,準(zhǔn)備進(jìn)行重命名\0====="
else
echo "在目錄:${export_ipa_path}/${ipa_name}.ipa 不存在999"
echo "\0=====exportArchive ipa包失敗 ?? ?? ?? \0====="
exit 1
fi
# 修改ipa文件名稱
mv $export_ipa_path/$scheme_name.ipa $export_ipa_path/$ipa_name.ipa
# 檢查文件是否存在
if [ -f "$export_ipa_path/$ipa_name.ipa" ] ; then
echo "\0=====導(dǎo)出 ${ipa_name}.ipa 包成功 ?? ?? ?? \0====="
# open $export_path
else
echo "在目錄:${export_ipa_path}/${ipa_name}.ipa 不存在xx1"
echo "\0=====導(dǎo)出 ${ipa_name}.ipa 包失敗 ?? ?? ?? \0====="
exit 1
fi
# 刪除export_options_plist文件(中間文件)
if [ -f "$export_options_plist_path" ] ; then
#echo "${export_options_plist_path}文件存在,準(zhǔn)備刪除"
rm -f $export_options_plist_path
fi
# 輸出打包總用時
echo "\0=====使用AutoPackageScript打包總用時: ${SECONDS}s \0====="
#上傳ipa到蒲公英 我自己加的
if [ -f "${export_ipa_path}/${ipa_name}.ipa" ]
then
echo '開始上傳ipa/apk到蒲公英'
curl -F "file=@${export_ipa_path}/${ipa_name}.ipa" -F "_api_key=${api_key}" 'http://www.pgyer.com/apiv2/app/upload'
else
echo "在目錄:${export_ipa_path}/${ipa_name}.ipa 不存在"
fi
mv "${export_ipa_path}/${ipa_name}.ipa" "${export_ipa_path}/${ipa_name}-${method}-${build_configuration}.ipa"
echo "\0\0"
echo "\0====完成\0===== ?? ?? ??"
exit 0