fastlane自动打包上传到蒲公英

一、安装fastlane

1、安装xcode命令行工具

xcode-select --install

如果提示

zhangxiongwen@zxw-MacBook-Pro SmartBulb % xcode-select --install  
xcode-select: error: command line tools are already installed, use "Software Update" to install updates  

就说明已经安装过了

二、安装Fastlane

sudo gem install fastlane -NV 或是 brew install fastlane 我这里使用 brew 安装的,
安装完了执行fastlane --version,确认下是否安装完成和当前使用的版本号。

三、初始化Fastlane

cd到项目目录执行

fastlane init
image.png

1:自动截屏。这个功能能帮我们自动截取APP中的截图,并添加手机边框(如果需要的话)
2:自动发布beta版本用于TestFlight
3:自动发布到AppStore
4:手动设置
我在这里选的是第四个(大家可根据自己需要选择)

紧接着一直点击enter键,知道安装成功会出现如下截图


image.png

安装成功之后,会在我们的工程目录生成一个fastlane文件夹:


image.png

Appfile不用管,需要编辑Fastfile文件

default_platform(:ios)

platform :ios do
  #这里是指令描述
  desc "Description of what the lane does"
  #这里是指令执行 例如:lane :custom_lane do 在终端运行 fastlane custom_lane
  lane :custom_lane do

    # add actions here: https://docs.fastlane.tools/actions
    #automatic_code_signing和gym都是fastlane命令 可以查阅相关文档
    #指定签名参数
    automatic_code_signing(
    #路径
        path: "SmartBulb.xcodeproj",
    #证书
        code_sign_identity: "Apple Distribution: Shenzhen XXX Technology Company Limited (R5A35URG47)",
        #描述文件 Mac上描述文件路径 ~/Library/MobileDevice/Provisioning Profiles
        profile_name: "-lunar adhoc"
    )

    #获取plist里面的一些值
    APPNAME = get_info_plist_value(path: "./SmartBulb/Info.plist", key: "CFBundleDisplayName")
    APPVERSION = get_info_plist_value(path: "./SmartBulb/Info.plist", key: "CFBundleShortVersionString")
    APPBUILD = get_info_plist_value(path: "./SmartBulb/Info.plist", key: "CFBundleVersion")

    #指定构建参数
    gym(
        workspace: "SmartBulb.xcworkspace",
        clean: true,
        configuration: "Release",
        export_method: "ad-hoc",
        # #{APPNAME} 表示在字符串中使用APPNAME的值
        output_name: "#{APPNAME}_#{APPVERSION}.#{APPBUILD}",
        output_directory: "./fastlane/package",
        archive_path: "./fastlane/package/archive"
    )
    
    #上传蒲公英
    pgyer(api_key: "xxxxxxxxxxx", user_key: "xxxxxxxxxxx")

  end
end

在终端运行 fastlane custom_lane就可以自动打包并上传到蒲公英了

如果需要上传到蒲公英,详见蒲公英官方文档
https://www.pgyer.com/doc/view/fastlane

你可能感兴趣的:(fastlane自动打包上传到蒲公英)