fastlane 实现ios App自动打包并上传appStore

文档:https://docs.fastlane.tools/codesigning/getting-started/
https://docs.fastlane.tools/actions/build_ios_app/#parameters

2019年5月27日 \
1.成功打development包 开发包 (可以用itools安装)

  desc "上传到sentry"
  lane :gymsit do
  #download_dsyms
  gym(
      configuration: "Debug-SIT",
      scheme: "317hu-SIT",
      workspace: "317hu.xcworkspace",
      export_method: "development",
      include_bitcode: false,
      output_name: "317hu-SIT",
      )
  end

2.成功打企业版包,打出的包可以上传蒲公英

  lane :gymsit do
  #download_dsyms
  gym(
      scheme: "PICC-SIT",
      workspace: "PICC.xcworkspace",
      include_bitcode: false,
      export_method: "enterprise",
      output_name:"PICC-sit",
      )
  end

2018年9月6日

一.第一版本也可以直接上传appstore,

1.先在appstoreconnect创建相关引用,填上所有信息,含图片

2.在项目里删除原来的faslane文件夹,用sudo fastlane init创建上传相关文件

3.直接用fastlane qqhl_release 上传即可。

2017年5月25日
一.fastlane
主要功能:自动部署和上传 app 到应用市场(android app也可以)。
1.官网https://fastlane.tools/
文档
https://docs.fastlane.tools/

二.安装(Homebriew)其他方法参照上面文档
1 保证最新的xocde 命令工具

xcode-select --install

2.安装

brew cask install fastlane

报错 No available Cask for fastlane
解决 brew cask update( poff 先关闭翻墙)
接下来 brew cask install fastlane
3.安装成功示意图

image.png

3.1其实上面可能还有问题
image.png

解决

echo 'export PATH="$HOME/.fastlane/bin:$PATH"' >> ~/.bash_profile

另外如果你发现.profile文件的变量不起作用了,在.bash_profile文件下如下命令既可

[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile

三.相关配置文件创建
1.cd到根目录

cd /Users/yanchengyi/Documents/317hu
image.png

2.初始化(输入相关信息)

fastlane init
image.png

生成如下文件

image.png

2.可能会没有创建 DeliverFile等文件,继续init

deliver init //(如果报错按报错说明,用 fastlane update_fastlane 更新)
image.png

3.配置文件操作(主要是Fastflie 和 Deiverfile)
3.1.Fastflie 文件编写 (主要是定义ygy_release action,其他基本上是默认创建的

# Customise this file, documentation can be found here:
# https://github.com/fastlane/fastlane/tree/master/fastlane/docs
# All available actions: https://docs.fastlane.tools/actions
# can also be listed using the `fastlane actions` command

# Change the syntax highlighting to Ruby
# All lines starting with a # are ignored when running `fastlane`

# If you want to automatically update fastlane if a new version is available:
# update_fastlane

# This is the minimum version number required.
# Update this, if you use features of a newer version
fastlane_version "2.28.3"

default_platform :ios

platform :ios do
  before_all do
    # ENV["SLACK_URL"] = "https://hooks.slack.com/services/..."
    #cocoapods   #1.我们注释掉了,因为代码里面就有pods库代码
    
  end

  desc "Runs all the tests"
  lane :test do
    scan
  end

  desc "Submit a new Beta Build to Apple TestFlight"
  desc "This will also make sure the profile is up to date"
  lane :beta do
    # match(type: "appstore") # more information: https://codesigning.guide
    gym(scheme: "317hu") # Build your app - more options available
    pilot

    # sh "your_script.sh"
    # You can also use other beta testing services here (run `fastlane actions`)
  end

  desc "Deploy a new version to the App Store"
  lane :release do
    # match(type: "appstore")
    # snapshot
    gym(scheme: "317hu") # Build your app - more options available
    deliver(force: true)
    # frameit
  end

#2.定义自定义lane
  desc "自定义lane"
  lane :ygy_release do
  #2.1编译 选择scheme和功能
    # 增加build版本号
    increment_build_number
    gym(
      scheme: "317hu",
      workspace: "317hu.xcworkspace",
      include_bitcode: false
      )

    deliver(
    #2.2上传appstore
      force: true,
      # skip_metadata: true,
      skip_screenshots: true,
      # skip uploading an ipa or pkg to iTunes  如果有最新包ipa包上传一定要 fasle
      skip_binary_upload: false,
      submit_for_review: true,
      automatic_release: true,
      price_tier: 0
      ) 
  end

  # You can define as many lanes as you want

  after_all do |lane|
    # This block is called, only if the executed lane was successful

    # slack(
    #   message: "Successfully deployed new App Update."
    # )
  end

  error do |lane, exception|
    # slack(
    #   message: exception.message,
    #   success: false
    # )
  end
end


# More information about multiple platforms in fastlane: https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Platforms.md
# All available actions: https://docs.fastlane.tools/actions

# fastlane reports which actions are used
# No personal data is recorded. Learn more at https://github.com/fastlane/enhancer

3.1.1如果设置了自动升级bulid版本号increment_build_number,工程属性需要如下设置

image.png

3.2Deiverfile文件编写 (主要用来写下更新说明,以及是否有广告标识之类设置)

###################### More Options ######################
# If you want to have even more control, check out the documentation
# https://github.com/fastlane/fastlane/blob/master/deliver/Deliverfile.md

###################### Automatically generated ######################
# Feel free to remove the following line if you use fastlane (which you should)

# 1 app_identifier
app_identifier "com.317hu.xxxx" # The bundle identifier of your app
# 2 用户名,Apple ID电子邮件地址
username "xx@xx.com" # your Apple ID user
# 3 提交审核信息
submission_information({
  export_compliance_encryption_updated: false,
  export_compliance_uses_encryption: false,
  content_rights_contains_third_party_content: false,
  add_id_info_uses_idfa: true,
  add_id_info_serves_ads: true,
  add_id_info_limits_tracking: true
})
#4 更新说明
release_notes({
  'zh-Hans' => "1、更新app图标;
2、app交互全面改版,具体内容分类显示;
3、详细内容增加字体大小设置功能。"
})

3.3 Appfile文件 (apple_id team_id账号等)
用终端命令默认创建的即可,不要特别修改

四.使用
1.切换到根目录

cd /Users/yanchengyi/Documents/317hu
fastlane ygy_release

2.成功效果(大概终端命令要执行20分钟左右)

image.png
image.png
image.png

五.补充
1.查看 Deliverfile可以添加的元素

fastlane action deliver

image.png

2.注意事项
2.1第一次 都需要fastlane init或者deliver init来创建配置文件,很多metadata里面的元素,其实都是itunes connect网站里面获取的,
2.2 如果网站的内容(如联系方式,测试账号密码等)没有修改,其实不需要在init, 直接fastlane ygy_release(自定义用来上架appstore的action)
大概终端命令要执行20分钟左右(如果5分钟,你很可能没有上传ipa, 该值一定要skip_binary_upload: false,)
2.3.很多metadata里面的元素,其实也可以在Deliverfile文件里面定义,一般优先读取Deliverfile文件,没有在读metadata
eg:
image.png

  1. 版本号其实是读工程这个文件的

image.png

4.编译带参数的lane 选自如下博客http://www.jianshu.com/p/840943eff17b

# You can define as many lanes as you want
desc "Deploy a new version to the App Store"
lane :release do |op|
    increment_version_number(version_number: op[:version]) #根据入参version获取app版本号
    increment_build_number(build_number: op[:version])  #将build号设置与app版本号相同

    # 设置app的info.plist文件项
    set_info_plist_value(path: "./xxx/Info.plist",  #info.plist文件目录
                        key: "UIFileSharingEnabled",  # key,将plist文件以Source Code形式打开可查询对应的key
                        value: false)  # value

    # 设置自定义plist文件项,用于给app配置不同的服务器URL
    set_info_plist_value(path: "./xxx/hostAddress.plist",
                        key: "host",
                        value: "https:/zhengshiServer:xx/xxx/xxx")

    # 更新Provisioning Profile
    # 在项目当前目录下创建provisions文件夹,并将App Store版本的.mobileprovision文件保存在里面,名称随意。
    update_project_provisioning(profile: "./provisions/appstore.mobileprovision")

    # 更新项目团队
    update_project_team(path: "xxx.xcodeproj",
                  teamid: "5JC8GZ432G")

    # 开始打包
    gym(use_legacy_build_api: true,
        output_name: "appstore",  # 输出的ipa名称
        silent: true,  # 隐藏没有必要的信息
        clean: true,  # 在构建前先clean
        configuration: "Release",  # 配置为Release版本
        codesigning_identity: "iPhone Distribution: xxx Co.,Ltd. (5JC8GZ432G)",  # 代码签名证书
        buildlog_path: "./fastlanelog",  # fastlane构建ipa的日志输出目录
        output_directory: "/Users/xxx/Desktop")  # ipa输出目录

end

4.1使用:

fastlane release version:1.0.2 // 打包App Store版本ipa,app版本号为1.0.2

如果您发现本文对你有所帮助,如果您认为其他人也可能受益,请把它分享出去。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 157,198评论 4 359
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,663评论 1 290
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 106,985评论 0 237
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,673评论 0 202
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 51,994评论 3 285
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,399评论 1 211
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,717评论 2 310
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,407评论 0 194
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,112评论 1 239
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,371评论 2 241
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,891评论 1 256
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,255评论 2 250
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,881评论 3 233
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,010评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,764评论 0 192
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,412评论 2 269
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,299评论 2 260

推荐阅读更多精彩内容