ios自動打包使用fastlane
1、首先安裝xcode
首先檢查是否已經安裝 Xcode 命令行工具,fastlane 使用 xcodebuild
命令進行打包,運行 xcode-select --install
命令,根據你的情況進行不同處理。
2、沒有彈出提示,命令行提示 xcode-select: note: install requested for command line developer tools
, 則需要運行下面命令,指定 Xcode 命令行工具所在的路徑。
$ xcode-select -p // 打印 Xcode 開發目錄
/Applications/Xcode.app/Contents/Developer
$ xcode-select --switch /Applications/Xcode.app/Contents/Developer //進行選擇
安裝 fastlane:
sudo gem install fastlane --verbose
安裝成功后查看版本:fastlane --version
初始化:fastlane
進入項目目錄,進行初始化操作
fastlane init
選擇4、進行自定義操作
補充:
1.fastlane 初始化默認會創建三個文件:Fastfile、Appfile、Deliverfile;兩個文件夾:metadata、screenshots
2.Fastfile : 核心文件,主要用於 命令行調用和處理具體的流程,lane相對於一個方法或者函數
3.Appfile : 存儲有關開發者賬號相關信息
4.Deliverfile: deliver工具的配置文件
安裝蒲公英的 fastlane 插件
$ fastlane add_plugin pgyer
安裝g工具
sudo gem install gym
bundle install --path vendor/bundle
gem install xcode-select
security unlock-keychain -p 1234 /Users/shangying/Library/Keychains/Login.keychain
打包前,需要開發進行xcode證書配置完成
配置完成后,mac電腦上需要進行一次完整打包過程才可以
腳本是初始化生成的文件,如
/Users/shangying/ios-workspace/syhospital-p-ios/fastlane
腳本配置:
macos:fastlane SY$ vim Fastfile
default_platform(:ios)
platform :ios do
desc "Description of what the lane does"
lane :p do
gym(
clean:true,
scheme:"sy_user_ios_qa",
export_method:"ad-hoc",
#output_name: output_name,
output_directory:"./build",
)
pgyer(api_key: "9b0d93c5............5d0", user_key: "e60b..............b2f4275df4d31")
end
end
appfile文件里寫id
如:
app_identifier "com.syxxxxxx.user"
編寫腳本進行執行如:
macos:scripts SY$ cat ios-p-app.sh
#!/bin/bash
cd /Users/shangying/ios-workspace/syhospital-p-ios
git checkout qa
git pull
/usr/local/bin/fastlane p
curl -F "file=@/Users/shangying/ios-workspace/syhospital-d-ios/build/sy_doctor_ios_qa.ipa" \
-F "uKey=e60baa4e2c80**********1" \
-F "_api_key=9b0d9****************" \
https://www.pgyer.com/apiv1/app/upload
說明:
jenkins執行shell腳本需要注意,環境變量需要帶上
#!/bin/bash
export LANG=zh_CN.UTF-8
source ~/.bash_profile
export PATH=$PATH:/Library/Ruby/Gems/2.3.0/gems/xcpretty-0.3.0/bin
sh /Users/shangying/scripts/ios-d-app.sh*
異常:
如果打包出現異常,提示權限不正確解決方案:
添加命令 security unlock-keychain -p password /Users/username/Library/Keychains/Login.keychain
https://www.jianshu.com/p/b03e59560d31
lane的名稱一定不能有特殊符號如-等,需要為str字符串類型(巨坑)
參考文檔:
http://www.cocoachina.com/ios/20180516/23396.html
https://www.jianshu.com/p/9d53836a3b64
http://www.cocoachina.com/ios/20150728/12733.html