League2eb

前言

更新Xcode11 + macOS Catalina後原本的腳本就失效覺得很賭爛,光是解決該問題就花了我六小時所以果斷寫成一篇流程,跟著走絕對可以OneKeyToBuild !
備註:OneKeyToBuild源自於OneKeyToWin外掛,有興趣自己Google

安裝Fastlane

  • 先打開終端機(別覺得我說廢話,我曾經就是不知道網路上這些指令要在哪裡下)
  • 安裝xcode-select
1
xcode-select --install
  • 使用homebrew,安裝Fastlane
1
brew cask install fastlane

先產生Certificate Signing Request

  • 打開mac裡面的鑰匙圈

  • 選擇製作本地要求憑證

  • 選擇儲存到磁碟,並且輸入email與名稱,認真可以隨便打

  • 儲存到桌面或者任何地方,用完可以刪除不刪除也可以(未來搞不好又用到,例如申請推播)
  • 長這樣

憑證設定(這邊以正式發佈證書來做為範例)

  • 去開發者帳號後台選擇Certificates, Identifiers & Profile

  • 點選加號來新增開發者證書

  • 選擇Apple Distribution後點選右上角Continue
    • 這邊特別說明一下從Xcode11之後只需要下載Apple Distribution or Apple Development就可以簽署所有平台應用包刮MacOS iPadOS

  • 點擊Choose File後找到已經製作好的Certificate Signing Request

  • 好,我就當做你現在不知道要選擇哪個檔案那就看圖,有沒有覺得剛剛才看過?

  • 選完之後點擊點選右上角Continue後會出現這個畫面,再點擊下載

  • 點兩下加入到Mac的鑰匙圈

新增一個App Identifiers

  • 點擊藍色 + 新增一個應用ID

  • 選擇 App IDs

  • 填寫應用資訊

設定發佈憑證

  • 點擊左邊Profile並點擊藍色+進行憑證新增

  • 選擇App Store 後點擊右上角Continue

  • 選擇上一個環節所建立好的App Identifiers,並點擊右上角Continue

  • 如果沒有意外你應該只有一個選項

  • 設定描述檔的名稱
    • 我會這樣寫HelloMyDemo_Release

  • 下載描述檔,然後建議把該描述檔放到你的專案資料夾裡面

    • 為什麼?好管理阿不然你一百個應用一百個描述檔你檔案會很難找

    • 懂得分類的是身為工程師的基本技能

Xcode內設定

  • 選擇Signing & Capabilities

    • 選擇Release(看箭頭)
    • 取消自動簽署(不要問為什麼,你會怕)
  • import上一個環節建立的描述檔案

新增打包ReleaseExportOptions.plist

  • 打開文字編輯器或者Sublime然後把下面的Code貼上
    • 修完畢後把該檔案儲存在專案資料夾內
    • 命名為ReleaseExportOptions.plist
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>compileBitcode</key>
<true/>
<key>destination</key>
<string>export</string>
<key>method</key>
<string>Release</string>
<key>provisioningProfiles</key>
<dict>
<key>應用BundleID ex: com.xx.sample</key>
<string>描述檔名稱就好,後面的mobileprovision不用</string>
</dict>
<key>signingCertificate</key>
<string>看鑰匙圈裡面憑證的名稱,整個複製上來 ex: Apple Distribution: 你的名稱 (1234567890)</string>
<key>signingStyle</key>
<string>manual</string>
<key>stripSwiftSymbols</key>
<true/>
<key>teamID</key>
<string>跟上面的1234567890一樣</string>
<key>thinning</key>
<string>&lt;none&gt;</string>
</dict>
</plist>

新增打包腳本

  • 打開文字編輯器或者Sublime然後把下面的Code貼上
    • 申請專用密碼
    • 修改下面內容
      • 帳號
      • 專用密碼
      • scheme
    • 修完畢後把該檔案儲存在專案資料夾內
    • 命名為Release.sh
    • 打開終端機cd到專案資料夾
    • 指令 chmod +x Release.sh (打開檔案權限)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#設置超時
export FASTLANE_XCODEBUILD_SETTINGS_TIMEOUT=120
#APP Store帳號
A="example@gmail.com"
#專用密碼密碼
P="這個密碼是專用密碼,不是開發者帳號的密碼"
#計時
SECONDS=0
#假設腳本放置在與項目相同的路徑下
project_path=$(pwd)
#取當前時間字符串添加到文件結尾
now=$(date +"%Y_%m_%d_%H_%M_%S")
#指定項目的scheme名稱
scheme="scheme名稱 ex : HelloMyDemo"
#指定要打包的配置名
#測試環境測試包 configuration="Debug"
#正式環境測試包 configuration="Release"
configuration="Release"
#指定打包所使用的輸出方式,目前支持app-store, package, ad-hoc, enterprise, development, 和developer-id,即xcodebuild的method參數
export_method='app-store'
#指定項目地址
workspace_path="$project_path/${scheme}.xcworkspace"
#指定輸出路徑
output_path="$project_path/build/"
#指定輸出歸檔文件地址
archive_path="$output_path/${scheme}_${now}.xcarchive"
#指定輸出ipa地址
ipa_path="$output_path/${scheme}_${now}.ipa"
#指定輸出ipa名稱
ipa_name="${scheme}_${now}.ipa"
#獲取執行命令時的commit message
commit_msg="$1"
#同意訪問鑰匙圈
allowPV="-allowProvisioningUpdates"
#ApplicationLoader路徑
altoolPath="/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool"
#打包的plist設定
exoplist="$project_path/ReleaseExportOptions.plist"
#輸出設定的變量值
echo "===workspace path: ${workspace_path}==="
echo "===archive path: ${archive_path}==="
echo "===ipa path: ${ipa_path}==="
echo "===export method: ${export_method}==="
echo "===commit msg: $1==="
#先清空前一次build
fastlane gym --silent true --workspace ${workspace_path} --scheme ${scheme} --clean --configuration ${configuration} --archive_path ${archive_path} --export_method ${export_method} --output_directory ${output_path } --output_name ${ipa_name} --export_xcargs ${allowPV} --export_options ${exoplist}
#上傳到iTunes Connect
"$altoolPath" --upload-app -f ${ipa_path} -t ios -u "$A" -p "$P"
osascript -e 'display notification "上傳完成"'
#輸出總用時
echo "===Finished. Total time: ${SECONDS}s==="

打包

  • cd 到專案目錄底下
  • 指令 ./Release.sh
  • 這個腳本有替您自動上傳到開發者帳號裡面的App Store Connect,但前提是你要先創好應用…(廢話)

 評論