自己項(xiàng)目的Fastfile文件配置,項(xiàng)目有內(nèi)測(cè)與發(fā)布對(duì)應(yīng)的target,證書(shū)為手動(dòng)指定,供大家參考。
- 1,自動(dòng)增加BuildNumber
- 2,自動(dòng)上傳蒲公英(需要安裝蒲公英插件)
- 3,自動(dòng)上傳Appstroe
使用方法 cd到項(xiàng)目.xcworkspace目錄 終端輸入 fastlane ad 或 fastlane release
# 定義fastlane版本號(hào)
fastlane_version "2.63.0"
# 定義打包平臺(tái)
default_platform :ios
# 項(xiàng)目ID
project_identifier = "com.tyfocg.app"
# 項(xiàng)目的內(nèi)測(cè)scheme名稱(chēng)
project_ad_scheme = "tyfocg_dev"
# 項(xiàng)目的發(fā)布scheme名稱(chēng)
project_release_scheme = "tyfocg_release"
# 項(xiàng)目的內(nèi)測(cè)描述文件名稱(chēng)
project_ad_provisioningProfiles = "tyfocgApp_ad_0516"
# 項(xiàng)目的發(fā)布描述文件名稱(chēng)
project_release_provisioningProfiles = "tyfocgApp_release_0516"
# 默認(rèn)內(nèi)測(cè)打包方式,目前支持app-store, package, ad-hoc, enterprise, development
# 注:由于如果使用手動(dòng)配置證書(shū),在export_options指定打包方式!
ipa_exportMethod = "ad-hoc"
# .ipa文件輸出路徑
ipa_outputDirectory = "~/Desktop/fastlaneBuild"
# 蒲公英api_key和user_key
pgyer_apiKey = "5b3a4b2fa....."
pgyer_userkey = "8d7ad3c1...."
# 計(jì)算buildNumber
def updateProjectBuildNumber
currentTime = Time.new.strftime("%Y%m%d")
build = get_build_number()
if build.include?"#{currentTime}."
# => 為當(dāng)天版本 計(jì)算迭代版本號(hào)
lastStr = build[build.length-2..build.length-1]
lastNum = lastStr.to_i
lastNum = lastNum + 1
lastStr = lastNum.to_s
if lastNum < 10
lastStr = lastStr.insert(0,"0")
end
build = "#{currentTime}.#{lastStr}"
else
# => 非當(dāng)天版本 build 號(hào)重置
build = "#{currentTime}.01"
end
puts("*************| 更新build #{build} |*************")
# => 更改項(xiàng)目 build 號(hào)
increment_build_number(
build_number: "#{build}"
)
end
# 所有任務(wù)腳本
platform :ios do
# ----------------------- 打包內(nèi)測(cè).ipa文件 -----------------------
lane :ad do|options|
branch = options[:branch]
puts "*************| 開(kāi)始打包.ipa文件... |*************"
# 更新項(xiàng)目build號(hào)
updateProjectBuildNumber
# 開(kāi)始打包
gym(
# 指定輸出的ipa名稱(chēng)
output_name:"#{project_ad_scheme}_#{get_build_number()}",
# 指定項(xiàng)目的scheme
scheme:"#{project_ad_scheme}",
# 是否清空以前的編譯信息 true:是
clean:true,
# 指定打包方式,Release 或者 Debug
configuration:"Release",
# 指定打包方式,目前支持app-store, package, ad-hoc, enterprise, development
# 注:由于使用手動(dòng)配置證書(shū),在export_options指定打包方式
#export_method:"#{ipa_exportMethod}",
# 指定輸出文件夾
output_directory:"#{ipa_outputDirectory}",
# Xcode9將不會(huì)允許你訪(fǎng)問(wèn)鑰匙串里的內(nèi)容,除非設(shè)置allowProvisioningUpdates
export_xcargs:"-allowProvisioningUpdates",
# 隱藏沒(méi)有必要的信息
silent:true,
# 手動(dòng)配置證書(shū),注意打包方式需在export_options內(nèi)使用method設(shè)置,不可使用export_method
export_options: {
method:"#{ipa_exportMethod}",
provisioningProfiles: {
"#{project_identifier}":"#{project_ad_provisioningProfiles}"
},
}
)
puts "*************| 開(kāi)始上傳蒲公英... |*************"
# 開(kāi)始上傳蒲公英
pgyer(api_key: "#{pgyer_apiKey}", user_key: "#{pgyer_userkey}")
puts "*************| 上傳蒲公英成功?? |*************"
end
# ----------------------- 上傳AppStore -----------------------
lane :release do
puts "*************| 開(kāi)始上傳AppStore... |*************"
# 更新項(xiàng)目build號(hào)
updateProjectBuildNumber
gym(
# 指定輸出的ipa名稱(chēng)
output_name:"#{project_release_scheme}_#{get_build_number()}",
# 指定項(xiàng)目的scheme
scheme:"#{project_release_scheme}",
# 是否清空以前的編譯信息 true:是
clean:true,
# 指定打包方式,Release 或者 Debug
configuration:"Release",
# 指定打包方式,目前支持app-store, package, ad-hoc, enterprise, development
# 注:由于使用手動(dòng)配置證書(shū),在export_options指定打包方式
#export_method:"#{app-store}",
# 指定輸出文件夾
output_directory:"#{ipa_outputDirectory}",
# Xcode9將不會(huì)允許你訪(fǎng)問(wèn)鑰匙串里的內(nèi)容,除非設(shè)置allowProvisioningUpdates
export_xcargs:"-allowProvisioningUpdates",
# 隱藏沒(méi)有必要的信息
silent:true,
# 手動(dòng)配置證書(shū),注意打包方式需在export_options內(nèi)使用method設(shè)置,不可使用export_method
export_options: {
method:"app-store",
provisioningProfiles: {
"#{project_identifier}":"#{project_release_provisioningProfiles}"
},
}
)
deliver(
# 選擇跳過(guò)圖片和元數(shù)據(jù)上傳,自己去配置
skip_screenshots:true,
skip_metadata:true,
# 上傳所有信息到App Store
force:true,
)
puts "*************| 上傳AppStore成功?? |*************"
#發(fā)布testflight測(cè)試
# pilot
end
end
注意使用代理(如青花瓷),可能造成上傳Appstroe失??!
具體使用可參考 http://www.itdecent.cn/p/19ae8cc865b0