一、shell腳本自動化打包并上傳
腳本下載:https://gitee.com/jiahongling/autoPackShell.git
plist配置

配置.png

位置.png
在終端執(zhí)行腳本
$ ./shell
二、fastlane
fastlane安裝
$ sudo gem install fastlane

fastlane安裝.png
fastlane使用

fastlane使用.png
fastlane注意點:

使用注意.png
選擇上傳不同的平臺:

選擇項.png
錯誤原因

fastlaneError1.png

fastlaneError2.png
設置build自增

自增設置.png
配置Fastfile文件:

配置插件.png
添加上傳平臺
platform :ios do
desc "Push a new beta build to TestFlight"
lane :beta do
increment_build_number(xcodeproj: "ShellTest.xcodeproj")
build_app(workspace: "ShellTest.xcworkspace", scheme: "ShellTest")
upload_to_testflight
end
desc "Push a new release build to the 蒲公英"
lane :pgyAction do
increment_build_number(xcodeproj: "ShellTest.xcodeproj")
build_app(workspace: "ShellTest.xcworkspace", scheme: "ShellTest")
# 插件 --- 蒲公英
#fastlane search_plugins 查找插件
# fastlane add_plugin pgyer
# fastlane add_plugin firim
# fastlane add_plugin fastlane-plugin-version
pgyer(api_key:"xxx", user_key:"xxx")
end
desc "Push a new release build to the firim"
lane :firimAction do
increment_build_number(xcodeproj: "ShellTest.xcodeproj")
build_app(workspace: "ShellTest.xcworkspace", scheme: "ShellTest")
firim(firim_api_token:"xxx")
end
end
添加插件
$ fastlane add_plugin pgyer //蒲公英插件
$ fastlane add_plugin firim //fir插件
$ fastlane add_plugin fastlane-plugin-version //控制版本插件
上傳appstore test flight firim 蒲公英的Appfile,F(xiàn)astfile和隱藏文件.evn中的內容為:
Appfile
app_identifier ENV['App_Identifier']
apple_id ENV['Apple_Id']
itc_team_id ENV['Itc_Team_Id']
team_id ENV['Team_Id']

appfile.png
Fastfile
# This file contains the fastlane.tools configuration
# You can find the documentation at https://docs.fastlane.tools
#
# For a list of all available actions, check out
#
# https://docs.fastlane.tools/actions
#
# For a list of all available plugins, check out
#
# https://docs.fastlane.tools/plugins/available-plugins
#
# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane
default_platform(:ios)
platform :ios do
before_all do
#雙重認證時用到
ENV["FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD"] = "rxpc-vbrs-very-wbrq"
cocoapods(use_bundle_exec: FALSE)
puts "所有任務執(zhí)行開始了"
end
desc "上線 App Store"
lane :release do | options |
increment_build_number(xcodeproj: ENV['Xcodeproj'])
build_app(workspace: ENV['Workspace'], scheme: ENV['Scheme'])
upload_to_app_store
end
desc "上線 testflight"
lane :beta do | options |
increment_build_number(xcodeproj: ENV['Xcodeproj'])
build_app(workspace: ENV['Workspace'], scheme: ENV['Scheme'])
upload_to_testflight
end
desc "上線蒲公英"
lane :adhoc_pgy do |options|
increment_build_number(xcodeproj:ENV['Xcodeproj'])
currentTime = Time.new.strftime("%Y-%m-%d-%H-%M-%s")
logDirectory = "#{currentTime}.ipa"
build_app(
workspace: ENV['Workspace'],
scheme: ENV['Scheme'],
#configuration: "Debug",默認是Release模式,最終生成.ipa和.app.dSYM.zip,Debug模式不會生產.app.dSYM.zip,只生產.ipa
silent: true,
clean: true, #打包前clean項目
output_directory: ENV['Pgy_Output_Path'],
output_name: logDirectory,
export_xcargs: "-allowProvisioningUpdates",
export_method:"enterprise" #導出方式
)
#export_method: app-store、ad-hoc、development、enterprise
pgyer(api_key: ENV['Api_Key'],
user_key: ENV['User_Key'])
end
desc "上線firim"
lane :adhoc_firim do |options|
#increment_build_number(xcodeproj:ENV['Xcodeproj'])#該句作用:build自增
#setup_version_build是一個函數(shù),可以自定義version和build
setup_version_build(options)#例如:fastlane adhoc_firim version:13.1 build:2
build_app(
workspace: ENV['Workspace'],
scheme: ENV['Workspace'],
#configuration: "Debug",
silent: true,
clean: true,
output_directory: ENV['Firim_Output_Path'],
output_name: "MY.ipa",
export_xcargs: "-allowProvisioningUpdates",
export_method:"enterprise")
firim(firim_api_token:ENV['Firim_Token'])
end
desc "版本處理"
def setup_version_build(options)
increment_build_number(
build_number:options[:build]
)
increment_version_number(
version_number:options[:version]
)
end
after_all do |lane, options|
puts"結束了"
end
error do |lane, exception, options|
if options[:debug]
puts "Hi :)"
end
end
end
.evn
# bundle id
App_Identifier = "xxx"
# 開發(fā)者賬號 qi
Apple_Id = "xxx"
# 開發(fā)者App Store Connect Team ID
Itc_Team_Id = "xxx"
# 開發(fā)者TeamId
Team_Id = "xxx"
# project的target scheme名稱
Scheme = "ShellTest"
# 項目xcodeproj
Xcodeproj ="ShellTest.xcodeproj"
# 項目xcworkspace
Workspace="ShellTest.xcworkspace"
# ipa輸出路徑-- Appstore
Appstore_Output_Path = "build/appstore"
# ipa輸出路徑-- Firim
Firim_Output_Path = "build/firim"
# ipa輸出路徑-- 蒲公英
Pgy_Output_Path = "build/pgy"
# firim 的token
Firim_Token = "xxx"
# 蒲公英 的api_key
Api_Key = "xxx"
# 蒲公英 的user_key
User_Key = "xxx"

env.png
說明:

用法說明.png
xcodebuild API http://www.itdecent.cn/p/c32263138af3