Fastlane 实现xcode 打ipa包并上传到蒲公英


总述:需要的安装的插件:(通过终端安装) :fastlane,Xcode 命令行工具,pgyer;

步骤:

1:安装fastlane

1)首先要安装正确的 Ruby 版本,在终端窗口中用下列命令来确认:
ruby -v
终端反应:
macdeMacBook-Air:Desktop mac$ ruby -v
ruby 2.3.3p222 (2016-11-21 revision 56859) [universal.x86_64-darwin17]
2)然后检查 Xcode 命令行工具是否安装。在终端窗口中输入命令:
xcode-select --install
如果未安装,终端会开始安装,如果报错误:command line tools are already installed, use "Software Update" to install updates.代表已经安装。
终端反应:
macdeMacBook-Air:Desktop mac$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates


3)以上依赖配置好之后就可以通过 rubygem 进行安装了:
$ sudo gem install fastlane
终端反应:

macdeMacBook-Air:Desktop mac$ sudo gem install fastlane Password: Successfully installed fastlane-2.73.0 Parsing documentation for fastlane-2.73.0 Done installing documentation for fastlane after 9 seconds 1 gem installed


2、登录蒲公英 - > 选择文档选项 - > 选择下图中标红选项 -> 安装上传到蒲公英的插件pgyer


2.1)在终端中,输入以下命令,即可安装蒲公英的 fastlane 插件
fastlane add_plugin pgyer
这个插件忘记安装的话,会导致只打包ipa成功,无法自动上传到蒲公英

2.2)在 Fastlane 启动蒲公英插件
在使用 Fastlane 之前,我们首先需要在项目中初始化 Fastlane。首先进入 App 的开发目录,执行以下命令来初始化 Fastlane:
fastlane init
执行完这个命令后,项目的根目录会增加一个fastLane文件夹


2.3)fastlane文件夹里面有两个文件:Appfile 和 Fastfile,Fastfile文件需要自己配置修改,
这里,我们用 vim 打开:
vim ./fastlane/Fastfile

这里我上传一份本地修改好的Fastfile文件,替换原来的Fastfile即可:

扫描二维码关注公众号,回复: 2516180 查看本文章

# Customize this file, documentation can be found here:
# https://docs.fastlane.tools/actions/
# 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
min_fastlane_version("2.70.3")


default_platform(:ios)


platform :ios do
  before_all do
    # ENV["SLACK_URL"] = "https://hooks.slack.com/services/..."
    cocoapods(use_bundle_exec: false)
    # cocoapods
  end
 :wqi


  # desc "Submit a new Beta Build to Apple TestFlight"
  # desc "This will also make sure the profile is up to date"
  # lane :beta do
  #  # sync_code_signing(type: "appstore") # more information: https://codesigning.guide
  #  build_app # more options available
  #  upload_to_testflight


  #   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
#    # sync_code_signing(type: "appstore")
#    capture_screenshots
#    build_app # more options available
#    upload_to_app_store(force: true)
#    # frame_screenshots
#  end


  # You can define as many lanes as you want


  desc "内测版本"
  lane :adhoc do |options|
    get_certificates           # invokes cert
    get_provisioning_profile   # invokes sigh
    gym(
      clean:true, # 是否清空以前的编译信息 true:是
      scheme: "TestApp",
# 自己项目名称
      workspace: "
TestApp.xcworkspace", # 自己项目名称xcworkspace(使用cocoapods才会生成)
      export_method:"ad-hoc", #app-store ad-hoc
      configuration:"AdHoc",
      output_directory:"./fastlane/build",
# 打包后的 ipa 文件存放的目录
      export_xcargs: "-allowProvisioningUpdates", #访问钥匙串
      output_name:"TestApp.ipa",
 # ipa 文件名
      #silent:true,#隐藏没有必要的信息
      export_options: {
        provisioningProfiles: {
          "com.combatworld.honourcard" => "dis_profile0104"
# bundleid,打包用的证书名字
        }
      }
    )
    pgyer(api_key: "925b799ec8ce5d19910288cdde27bfdc",
# 从蒲公英项目详情中获取的 apikey
         user_key: "794c12895e9513258bf90331d9b6cc63",
# 从蒲公英项目详情中获取的 userkey
         update_description: options[:desc]#"description"
# 本次测试更新的文字说明(参数设置)




    )


  end
  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://docs.fastlane.tools/advanced/#control-configuration-by-lane-and-by-platform
# All available actions: https://docs.fastlane.tools/actions


# fastlane reports which actions are used. No personal data is recorded.
# Learn more at https://docs.fastlane.tools/#metrics



2.4 配置完成后,在项目根目录下执行(fastlane里配置了desc参数)

fastlane ios adhoc desc:test
在蒲公英中就会出现一个描述为test的新的版本


可参考的网址:http://www.cocoachina.com/ios/20170519/19317.html



猜你喜欢

转载自blog.csdn.net/wei371522/article/details/78988821