使用fastlane对iOS打包

Fastlane 简介

. Fastlane是一个通过简单命令来完成诸截图、获取证书、编译、导出安装包、上传到Fir 供测试使用、提交到APP STORE
. Fastlane安装文档

Jenkins简介

. Jenkins是一款开源CI&CD软件,用于自动化各种任务,包括构建、测试和部署软件
. Jenkins安装文档

Jenkins与Fastlane关系

. Jenkins配置项目相关参数,Fastlane在fastfile脚本中使用
.可以理解为Jenkins 快速帮你做一个网站然后调用Fastlane 经过一系列不走帮你导出安装包

今天重点介绍Fastlane配置(假设大家对jenkins、fastlane 已经安装好并有一定理解)

  1. 进入工程主目录 运行
fastlane init 
  1. 然后会创建以下文件


    fastlane-init.png
  2. 查看Appfile文件
 app_identifier "com.xxxx.xxxx" # The bundle identifier of your app
 apple_id "xxxxx" # Your Apple email address
  1. 配置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

# 平台,安卓还是iOS
default_platform(:ios) 

# iOS进行的操作
platform :ios do
  desc "企业版"
  # 在执行lane之前进行的操作,例如我们在每次打包之前都执行一次pod install
  #before_all do
    # faselane中pod install的操作
    #cocoapods
  #end

  # 打包的lane操作,我们可以配置多个lane来打不同环境的包
  lane :enterprise do |op|

    # 打包之前跟新指定配置的描述文件
    update_project_provisioning(
        # 之前有sigh下载的描述文件存储路径
        profile:"./XXXXDis.mobileprovision",

        # 打包配置,Debug,Release
        build_configuration:"Debug"
    )

      automatic_code_signing(
        # 工程文件所在路径
        path:"ProjectName.xcodeproj",
        # 是否使用自动签名,这里如果是打包的话应该一般都为false吧,默认也是false
        use_automatic_signing:false,
        # 打包的team ID, 也就是打包使用的证书中的team ID,这个如果不知道是什么的话可以在xCode中设置好签名用的描述文件后到xcodeproj下的pbxproj文件中搜索“DEVELOPMENT_TEAM”,它的值就是了
        team_id:"XXXX",
        # 这个就不用说了,需要修改的targets
        targets:"ProjectName",
        # 用哪种方式打包“iPhone Develop”还是“iPhone Distribution”
        code_sign_identity:"iPhone Distribution",
        # 描述文件名称, 也就是使用哪个描述文件打包
         profile_name:"XXXXDis"
    )

    currentTime = Time.new.strftime("%Y-%m-%d-%H-%M")
    outputDirectory = "./build/#{currentTime}"
    logDirectory = "#{outputDirectory}/fastlanelog"

    gym(
        # 打包方式,enterprise, adhoc,appstore,development
        export_method: "enterprise",
        scheme: "ProjectName",
        # pod 生成的workspace文件
        workspace:"ProjectName.xcworkspace",
        # 输出文件夹
        output_directory: outputDirectory,
        # 输出包名称
        output_name:"ProjectName.ipa",

        # 打包前是否clean
        clean:true,
        silent:true,
        # 打包的配置 Debug Release
        configuration:"Debug",
        # 打包日志输出文件夹
        buildlog_path:logDirectory,
        # 打包证书
        codesigning_identity:'iPhone Distribution: XXXXXXXXXXXX TECHNOLOGY CO.,LTD.',
        # Xcode 9 默认不允许访问钥匙串的内容,必须要设置此项才可以,运行过程可能会提示是否允许访问钥匙串,需要输入电脑密码
        export_xcargs: "-allowProvisioningUpdates",
        # 导出选项
        export_options:{
            # 打包导出时可选描述文件 "bundleID"=>"描述文件名称"
            provisioningProfiles: {
                "com.XXXX.XXXX" => "XXXXDis.mobileprovision",
            },
        }
    )
    archive_path="Published succeed:/XXXXXXXXXXXX/build/#{currentTime}/ProjectName.ipa"
    puts "#{archive_path}"
  end

  # 当lane执行完成之后进行哪些操作
  after_all do |lane|

  end

  error do |lane, exception|
  end

end

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容