安裝fastlane
至於fastlane是作什麼的就很少說了,自行百度;vue
sudo gem install fastlane --verbose
安裝成功後沒有修改gem source 的修改一下,我用的是https://gems.ruby-china.com/
終端打開項目目錄執行fastlane init, fastlane init執行過程當中須要選擇一些東西,如What would you like to use fastlane for? 並把Gemfile中的source修改爲你的gem source的源,ios
wk@wakedatadeMacBook-Pro uniapp-yuexiuhui-iOS % fastlane init [✔] 🚀 [✔] Looking for iOS and Android projects in current directory... [15:40:54]: Created new folder './fastlane'. [15:40:54]: Detected an iOS/macOS project in the current directory: 'uniapp-yuexiuhui-iOS.xcworkspace' [15:40:55]: ----------------------------- [15:40:55]: --- Welcome to fastlane 🚀 --- [15:40:55]: ----------------------------- [15:40:55]: fastlane can help you with all kinds of automation for your mobile app [15:40:55]: We recommend automating one task first, and then gradually automating more over time [15:40:55]: What would you like to use fastlane for? /usr/local/Cellar/fastlane/2.168.0/libexec/gems/highline-1.7.10/lib/highline.rb:624: warning: Using the last argument as keyword parameters is deprecated 1. 📸 Automate screenshots 2. 👩✈️ Automate beta distribution to TestFlight 3. 🚀 Automate App Store distribution 4. 🛠 Manual setup - manually setup your project to automate your tasks ? 這個地方輸入你要上傳到那個平臺,通常選二、三、4
下一步須要提醒你輸入的是你的iOS開發者帳號git
[15:44:09]: To use App Store Connect and Apple Developer Portal features as part of fastlane, [15:44:09]: we will ask you for your Apple ID username and password [15:44:09]: This is necessary for certain fastlane features, for example: [15:44:09]: [15:44:09]: - Create and manage your provisioning profiles on the Developer Portal [15:44:09]: - Upload and manage TestFlight and App Store builds on App Store Connect [15:44:09]: - Manage your App Store Connect app metadata and screenshots [15:44:09]: [15:44:09]: Your Apple ID credentials will only be stored in your Keychain, on your local machine [15:44:09]: For more information, check out [15:44:09]: https://github.com/fastlane/fastlane/tree/master/credentials_manager [15:44:09]: [15:44:09]: Please enter your Apple ID developer credentials /usr/local/Cellar/fastlane/2.168.0/libexec/gems/highline-1.7.10/lib/highline.rb:624: warning: Using the last argument as keyword parameters is deprecated [15:44:09]: Apple ID Username:
而後是iOS開發者帳號的密碼,若是你的帳號下面有多個企業或組織,而後是選擇證書而後就配置完了。
而後在你的項目目錄中會多一個fastlane文件夾,一個Gemfile,Gemfile中須要修改source就能夠了。fastlane中有兩個文件,一個Appfile一個Fastfile,Appfile保存的是iOS開發者帳號的信息和證書信息,Fastfile中是自動打包的腳本,對應純原生的代碼這樣基本就能夠了;
而對於如今混口開發盛行的時代,咱們項目基本都是uni-app寫的因此才須要再寫一些腳本,開發就是愈來愈懶,一步也不喜歡手動去作,那麼腳本的用處就大了;github
#!/bin/bash env=$1 buildUpdateDescription=$2 ipa_name="項目名" api_key="蒲公英的api_key" if [ ! -n "$1" ] ;then env="build" fi # 向iOS的Info.plist裏面寫值 # environment="production" # if [[ $env = "dev" ]]; then # environment="development" # fi # path=$(cd `dirname $0`; pwd) # target_plist="$path/uniapp-yuexiuhui-iOS/Info.plist" # echo $target_plist # for plist in "$target_plist"; do # if [[ -f "$plist" ]]; then # /usr/libexec/PlistBuddy -c "Set :Environment $environment" "$plist" # fi # done # 修改YXHCommon.m文件,這個的目的主要是切換生產環境與測試環境的,修改的值主要用於條件編譯 cd uniapp-yuexiuhui-iOS/utils if [[ "dev" = $env ]]; then sed -i '' 's/#if false/#if true/g' YXHCommon.m else sed -i '' 's/#if true/#if false/g' YXHCommon.m fi cd ../.. cd ../uniapp-yuexiuhui-vue # 而下面的npm run xxx這個主要是HbuilderX 打包腳本 if [ "dev" = $env ] then npm run dev:app-plus else npm run build:app-plus fi echo '------覆蓋www------' cp -R dist/$env/app-plus/ ../$ipa_name/$ipa_name/Pandora/apps/__UNI__E59AA60/www cd ../uniapp-yuexiuhui-iOS fastlane pgy cd ./build export_ipa_path=$(cd `dirname $0`; pwd) #上傳ipa到蒲公英 我本身加的 if [ -f "${export_ipa_path}/${ipa_name}.ipa" ] then echo '開始上傳ipa/apk到蒲公英' result=$(curl -F "file=@${export_ipa_path}/${ipa_name}.ipa" -F "_api_key=${api_key}" -F "buildUpdateDescription=${buildUpdateDescription}" 'http://www.pgyer.com/apiv2/app/upload') else echo "在目錄:${export_ipa_path}/${ipa_name}.ipa 不存在" fi echo '上傳到蒲公英成功' exit 0
2.上傳到TestFlight的腳本shell
#!/bin/bash env=$1 if [ ! -n "$1" ] ;then env="build" fi cd uniapp-yuexiuhui-iOS/utils if [[ "dev" = $env ]]; then sed -i '' 's/#if false/#if true/g' YXHCommon.m else sed -i '' 's/#if true/#if false/g' YXHCommon.m fi cd ../.. cd ../uniapp-yuexiuhui-vue if [ "dev" = $env ] then npm run dev:app-plus else npm run build:app-plus fi echo '------覆蓋www------' cp -R dist/$env/app-plus/ ../uniapp-yuexiuhui-iOS/uniapp-yuexiuhui-iOS/Pandora/apps/__UNI__E59AA60/www cd ../uniapp-yuexiuhui-iOS fastlane beta exit 0
3.若是運行腳本報錯請檢查shell語法,固然你也能夠用Python寫
若有什麼疑問能夠聯繫我:
WeChat:fengsh_h
e-mail: fengsh_h@aliyun.comnpm