iOS_fastlane 安装和上传到TestFlight,appstore,蒲公英

fastlane简介

fastlane 用于iOS和Android的自动化打包、发布等工作,可以节省大量无效时间。当然,fastlane不仅只能打包和发布,还有更强大的功能等着我们去发现


fastlane_text.png

参考网站

官网: https://docs.fastlane.tools

安装fastlane

  • 安装fastlane终端命令
sudo gem install fastlane 
这个命令安装之后有可能导致在终端输入`fastlane`命令的时候报错 zsh-commond  fastlane no found
这个时候可以用另一个安装fastlane的命令
brea install fastlane
  • 安装成功之后如下图显示


    image.png
  • 可以用命令fastlane --version来查看是否安装成功
    image.png

在项目中初始化fastlane 使用命令fastlane init

\color{#ee4000}{注意每个项目使用fastlane的时候,都需要在项目路径下面使用命令`fastlane init`来初始化}

  • 注:fastlane会提示我们使用它做什么
  • 选项1:自动截图。手动截图并将处理好后的图片发布到测试或线上平台上需要消耗大量的时间,fastlane可以简化这一步。(目前还没有测试这一选项,因为暂时没用到这个功能)
  • 选项2:将测试包发布到TestFlight。
  • 选项3:自动发布到App Store。
  • 选项4:手动设置(自定义发布平台如pgyer,firm等)。
    这里我们选择选项2。因为,我们需要将测试app提交到TestFlight。


    image.png
  • 输入您的苹果账号


    image.png
  • 一直按回车就可以了


    image.png
  • 初始化成功之后,项目目录会多了一下几个文件
  • Appfile : 苹果账号等信息
  • Fastfile: 这个就是我们要用来搞事情的文件了,刚刚我们选择了 2. 👩✈️ Automate beta distribution to TestFlight自动上传到TestFlight
  • 默认选择了2的情况下 Fastfile的内容:
default_platform(:iOS)

platform :iOS do
  desc "Push a new beta build to TestFlight"
  lane :beta do
    increment_build_number(xcodeproj: "TestDomain.xcodeproj")
    build_app(scheme: "TestDomain")
    upload_to_testflight
  end
end
  • 每一个lane就是一个任务,可以理解为你想干什么事情,在这里我们想做的就是上传到TestFlight。(注意一个Fastfile可以有多个lane任务,并且lane可以嵌套 fastlane的高级用法
image.png

上传到TestFlight

image.png
  • 打开终端到项目路径下面
fastlane  beta
  • 如下图就是上传成功了


    image.png

到此最简单的上传到TestFlight就完成了


上传到蒲公英

*蒲公英官方文档https://www.pgyer.com/doc/view/fastlane
获取API Key在个人基本资料里面可以找到

image.png


上传到appstore

  1. 在fastlane文件夹里面的Appfile 输入对应的信息
app_identifier("com.xxxx.t2023") # The bundle identifier of your app
apple_id("cx13xxxxx024@11126.com") # Your Apple email 

team_id("9VxxxxGJQ") # Developer Portal Team ID 这个在苹果
itc_team_id("xxxxxxx") # App Store Connect Team ID


1.获取team_id 可以参考https://sarunw.com/posts/fastlane-find-team-id/

image.png

  1. 获取itc_team_id 可以参考https://sarunw.com/posts/fastlane-find-team-id/
  2. 获取APP专用密码,这个是上传到APP Store的时候要求的,记得及时保存下来 不然看不到了


    image.png

异常处理 可以参考https://www.jianshu.com/p/ee542b7e4c99

] The request could not be completed because:
Invalid username and password combination. Used 'cx126.com ' as the username.



项目中的文件Fastfile


# Uncomment the line if you want fastlane to automatically update itself
# update_fastlane

fastlane_version "2.214.0"

default_platform(:ios)

# 项目ID
project_identifier_Dev = "xxx"
project_identifier_Dis = "xxxx"

# 测试环境scheme名称
project_Dev_scheme = "BSCater"
# 正式环境scheme名称
project_Dis_scheme = "BSCater"
# 发布环境scheme名称
project_App_scheme = "BSCater"

# 项目的描述文件名称(这里也可以配置一个通用的Adhoc文件)
project_provisioningProfiles_dev = "onlytest_AdHoc_dev"
project_provisioningProfiles_dis = "onlytest_AdHoc_dis"
project_provisioningProfiles_appstore = "onlytest_appstore"

# 默认内测打包方式,目前支持app-store, package, ad-hoc, enterprise, development
# 注:由于如果使用手动配置证书,在export_options指定打包方式!
ipa_exportMethod_adhoc = "ad-hoc"
ipa_exportMethod_appstore = "app-store"


#蒲公英pgyer_apiKey和pgyer_userkey 换成你的
pgyer_apiKey ="xxxx"
#这个可以不用
pgyer_userkey ="xxxx"


currentTime = Time.new.strftime("%Y%m%d")

ipa_name = "应用名"

# .ipa文件输出路径
ipa_outputDirectory_Debug = "~/Desktop/IPA/#{ipa_name}/Dev/#{currentTime}"
ipa_outputDirectory_Release = "~/Desktop/IPA/#{ipa_name}/Dis/#{currentTime}"
ipa_outputDirectory_AppStore = "~/Desktop/IPA/#{ipa_name}/AppStore/#{currentTime}"


# 计算buildNumber
def updateProjectBuildNumber
currentTime = Time.new.strftime("%Y%m%d")
build = get_build_number()
if build.include?"#{currentTime}."
# => 为当天版本 计算迭代版本号
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
# => 非当天版本 build 号重置
build = "#{currentTime}.01"
end
puts("*************| 更新build #{build} |*************")
# => 更改项目 build 号
increment_build_number(
build_number: "#{build}"
)
end

platform :ios do
desc "Description of what the lane does"
lane :ad_dev do
puts "*************| 开始打包.ipa文件... |*************"
# 更新项目build号
updateProjectBuildNumber

#指定Xcode路径,装多个版本xcode时指定xcode版本
xcode_select("/Applications/Xcode.app")
#build_app(export_method: "ad-hoc")
# 开始打包
gym(
# 指定输出的ipa名称
output_name:"#{project_Dev_scheme}_#{get_build_number()}",
# 指定项目的scheme
scheme:"#{project_Dev_scheme}",
# 是否清空以前的编译信息 true:是
clean:true,
# 指定打包方式,Release 或者 Debug
configuration:"Release",
# 指定打包方式,目前支持app-store, package, ad-hoc, enterprise, development
# 注:由于使用手动配置证书,在export_options指定打包方式
export_method:"#{ipa_exportMethod_adhoc}",
# 指定输出文件夹
output_directory:"#{ipa_outputDirectory_Debug}",
# Xcode9将不会允许你访问钥匙串里的内容,除非设置allowProvisioningUpdates
export_xcargs:"-allowProvisioningUpdates",
# 隐藏没有必要的信息
silent:true,
# 手动配置证书,注意打包方式需在export_options内使用method设置,不可使用export_method
export_options: {
method:"#{ipa_exportMethod_adhoc}",
provisioningProfiles: {
"#{project_identifier_Dev}":"#{project_provisioningProfiles_dev}",
"#{project_identifier_Dis}":"#{project_provisioningProfiles_dis}"

},
}
)
puts "*************| 开始上传蒲公英... |*************"
# 开始上传蒲公英
# pgyer(api_key: "#{pgyer_apiKey}", password: "123456", install_type: "2")
pgyer(api_key: "#{pgyer_apiKey}", password: "123456", install_type: "2", update_description: "更新内容")
puts "*************| 上传蒲公英成功🎉 |*************"

end

desc "Description of what the lane does"
lane :ad_dis do
puts "*************| 开始打包.ipa文件... |*************"
# 更新项目build号
updateProjectBuildNumber

#指定Xcode路径,装多个版本xcode时需指定
#xcode_select("/Applications/Xcode.app")
#build_app(export_method: "ad-hoc")
# 开始打包
gym(
# 指定输出的ipa名称
output_name:"#{project_Dis_scheme}_#{get_build_number()}",
# 指定项目的scheme
scheme:"#{project_Dis_scheme}",
# 是否清空以前的编译信息 true:是
clean:true,
# 指定打包方式,Release 或者 Debug
configuration:"Release",
# 指定打包方式,目前支持app-store, package, ad-hoc, enterprise, development
# 注:由于使用手动配置证书,在export_options指定打包方式 如果是自动 直接配置这个
export_method:"#{ipa_exportMethod_adhoc}",
# 指定输出文件夹
output_directory:"#{ipa_outputDirectory_Debug}",
# Xcode9将不会允许你访问钥匙串里的内容,除非设置allowProvisioningUpdates
export_xcargs:"-allowProvisioningUpdates",
# 隐藏没有必要的信息
silent:true,
# 手动配置证书,注意打包方式需在export_options内使用method设置,不可使用export_method
#export_options: {
#method:"#{ipa_exportMethod_adhoc}",
# provisioningProfiles: {
# "#{project_identifier_Dev}":"#{project_provisioningProfiles_dev}",
# "#{project_identifier_Dis}":"#{project_provisioningProfiles_dis}"
#},
#}
)
puts "*************| 开始上传蒲公英... |*************"
puts "*************| "#{pgyer_apiKey}" |*************"
# 开始上传蒲公英
# pgyer(api_key: "#{pgyer_apiKey}", password: "123456", install_type: "2")
pgyer(api_key: "#{pgyer_apiKey}", password: "123456", install_type: "2", update_description: "哈哈哈哈哈哈哈")
puts "*************| 上传蒲公英成功🎉 |*************"

end


# ----------------------- 上传AppStore -----------------------
lane :aps do

puts "*************| 开始打包.ipa文件... |*************"

# 更新项目build号
updateProjectBuildNumber

gym(
# 指定输出的ipa名称
output_name:"#{project_App_scheme}_#{get_build_number()}",
# 指定项目的scheme
scheme:"#{project_App_scheme}",
# 是否清空以前的编译信息 true:是
clean:true,
# 指定打包方式,Release 或者 Debug
configuration:"Release",
# 指定打包方式,目前支持app-store, package, ad-hoc, enterprise, development
# 注:由于使用手动配置证书,在export_options指定打包方式
#export_method:"#{app-store}",
# 指定输出文件夹
output_directory:"#{ipa_outputDirectory_AppStore}",
# Xcode9将不会允许你访问钥匙串里的内容,除非设置allowProvisioningUpdates
export_xcargs:"-allowProvisioningUpdates",
# 隐藏没有必要的信息
silent:true,
# 手动配置证书,注意打包方式需在export_options内使用method设置,不可使用export_method
#export_options: {
#  method:"app-store",
#  provisioningProfiles: {
#     "#{project_identifier_Dev}":"#{project_provisioningProfiles_dev}",
#  "#{project_identifier_Dis}":"#{project_provisioningProfiles_appstore}"
# },
# }
)
puts "上传 ipa 包到 iTunes Connect"
deliver(
submission_information: {
add_id_info_limits_tracking: false,
add_id_info_serves_ads: false,
add_id_info_tracks_action: false,
add_id_info_tracks_install: false,
add_id_info_uses_idfa: false,
content_rights_has_rights: true,
content_rights_contains_third_party_content: true,
export_compliance_platform: 'ios',
export_compliance_compliance_required: false,
export_compliance_encryption_updated: false,
export_compliance_app_type: nil,
export_compliance_uses_encryption: false,
export_compliance_is_exempt: false,
export_compliance_contains_third_party_cryptography: false,
export_compliance_contains_proprietary_cryptography: false,
export_compliance_available_on_french_store: false
},
# 跳过截图上传
skip_screenshots: true,
# 跳过元数据上传
skip_metadata: false,
#跳过上传ipa或pkg到iTunes Connect,如果已上传就是true,反之false
skip_binary_upload: false,
# 跳过HTML预览文件的验证
force: true,
# 在上传所有内容后提交新版本进行审核
submit_for_review: true,
# 一旦应用程序审核通过,该应用会自动发布App Store
automatic_release: false
)
end




end

参考文章

  1. fastlane打包上传到appstore https://www.jianshu.com/p/5c629d42cda5
  2. https://www.jianshu.com/p/ee542b7e4c99
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容