初窥 fastlane 一键打包上传蒲公英平台和App Store

很久之前就听说自动化打包如何方便,只是自己一直没有去尝试过,最近因为项目需求,自己也尝试了一把。关于fastlane网上资料非常多,功能如何强大,自动化测试、证书管理、截屏等。但是我这里只使用自动化打包的功能,毕竟适合自己项目团队的方式才是最好的方式。

安装faltlane以及初始化项目fastlane

  • faltlane的安装就不讲了,请参考官方网站传送门

  • 进入项目工程,初始化fastlane

cd your project path
fastlane init

这里写图片描述

不知道为什么,用公司电脑每次进到这里就卡住了,翻了墙也不行,更改了源也不行,如果有小伙伴知道请给我留言,不过只要生成了fastlane/Fastfile 文件就行了,后面依然可以操作。

gem sources
https://gems.ruby-china.org/
https://rubygems.org
  • 添加蒲公英插件,成功后,fastlane文件夹出现Pluginfile文件
fastlane add_plugin pgyer

这里写图片描述

编写Fastfile,打包ad-hoc版本上传蒲公英

  • 编写Fastfile文件,见代码
default_platform(:ios)

platform :ios do
  desc "上传到蒲公英"
 # 使用方法:
 # 1、进入对应项目,添加蒲公英插件 fastlane add_plugin pgyer
 # 2、运行打包命令 fastlane adhoc name:your_project_name

  lane :adhoc do |options|
    name = options[:name]
    gym(
      clean:true, # 是否清空以前的编译信息 true:是
      scheme: name, # 自己项目名称
      workspace: "#{name}.xcworkspace", # 自己项目名称xcworkspace(使用cocoapods才会生成)
      export_method:"ad-hoc", #app-store,ad-hoc,enterprise,development
      configuration:"AdHoc",
      output_directory:"./fastlane/build", # 打包后的 ipa 文件存放的目录
      export_xcargs: "-allowProvisioningUpdates", #访问钥匙串
      output_name: "#{name}.ipa",# ipa 文件名
      silent:true,#隐藏没有必要的信息
      export_options: {
        provisioningProfiles: {
          "com.you.bundleIdentifier" => "your_AdHoc" # bundleid,打包用的证书名字
        }
      }
    )

    pgyer(
      api_key: "your_apikey", # 从蒲公英项目详情中获取的 apikey
      user_key: "userKey", # 从蒲公英项目详情中获取的 userkey
      password: "123456", # 密码
      update_description: "本次测试更新的文字说明"#"description" # 本次测试更新的文字说明(参数设置)
    )
  end
end

  • 使用方法
在终端进入项目路径执行命令:fastlane adhoc name:your_project_name
  • 打包之前,在Xcode中配置好Version和Build版本(这里没有使用插件,手动管理),证书要配置正确,之前这里配成了App Store的证书,打包会出现异常
    这里写图片描述

  • 打包上传成功的提示,然后会收到蒲公英的邮件或者短信提醒
    这里写图片描述

falstlane 打包上传App Store

之前在网上查看了一番别人的博客,总的来说就是不能直接拿来用。没办法,自己看了一遍官方文档,研究了一番,探索出了自己的一个版本.现将探索历程记录在下.

官方文档说要上传App Store需要使用deliver官方传送门

  • 第一步进入自己的项目工程初始化deliver
cd [your_project_folder]
fastlane deliver init

这个时候fastlane会让你输入开发者账号和APP的Bundle Identifier,如果Bundle Identifier和iTunes Store中任意一个不存在,deliver会初始化失败.
请在初始化之前创建对应的APP ID 和iTunes Store中创建对应APP.

初始化完成之后会,fastlane会下载iTunes Store中APP的配置信息(如果之前配置了)
效果如下:
这里写图片描述

这里写图片描述

  • 根据官方文档的描述,编写Deliverfile文件
    利用Deliverfile文件配置iTunes Store需要填写配置相关的信息(不明白的信息和iTunes Store中对照下就知道了)
# The Deliverfile allows you to store various iTunes Connect metadata
# For more information, check out the docs
# https://docs.fastlane.tools/actions/deliver/


# 根据iTunes Store 信息设置

username "12345678@qq.com"  # Apple ID email address

app_identifier("com.my.MyFastLaneDemo") # bundle identifier

#ipa("./fastlane/release_ipa/My.ipa") #  如果没有这个选项,只有metadata会被上传 ipa路径

copyright("版权信息 2018") #版权信息

#submit_for_review(false) #是否提交审核,true表示立马提交审核

screenshots_path("./fastlane/screenshots") # 截屏图片展示

price_tier 0 #app 出售价格

trade_representative_contact_information(  #iTunes store 综合信息处信息
  first_name: "jie", #名
  last_name: "wang", #姓
  address_line1: "软件园", #地址
  address_line2: "",
  address_line3: "",
  city_name: "Chengdu", # 城市
  state: "SICHUAN", # 省
  country: "China", #国家
  postal_code: "610000", # 邮编
  phone_number: "+86 18283606699", # 手机
  email_address: "2186682180@qq.com", #邮箱
)


app_review_information( # app审核信息
  first_name: "jie", # 名
  last_name: "wang", #姓
  phone_number: "+86 18283606699", #联系信息电话号码
  email_address: "2186682180@qq.com", #联系信息邮箱
  demo_user: "12345678",  #审核测试账号
  demo_password: "1234", # 审核测试密码
  notes: "备注信息" # iTunes Store 审核信息备注
)

#提交审核信息:加密, idfa 等
submission_information({    # 参数参考地址  https://github.com/fastlane/fastlane/blob/master/spaceship/lib/spaceship/tunes/app_submission.rb
    export_compliance_encryption_updated: false,
    export_compliance_uses_encryption: false,
    content_rights_contains_third_party_content: false,
    add_id_info_uses_idfa: false
})


# 模板参考地址 https://github.com/fastlane/fastlane/blob/master/deliver/assets/example_rating_config.json
app_rating_config_path "./fastlane/metadata/itunes_rating_config.json" #年龄分级配置

name({
'zh-Hans' => "MyFastLaneDemoTest"  # app名称
})

description({ #iTunes Store 中描述信息
  'zh-Hans' => "APP的描述信息,用于APP功能的描述和介绍不能少于10个字符"
})

release_notes({
  'zh-Hans' => "第一个版本测试" #这个新版本信息,iTunes Store 新增内容处该填的内容
})

keywords( # 收缩关键词
  "zh-Hans" => "FastLane, 美女"
)

promotional_text( # 本地化宣传文本信息介绍
  "zh-Hans" => "本地化宣传文本信息介绍",
)

support_url({ # 技术支持网址(URL)
  'zh-Hans' => "http://www.baidu.com"
})

marketing_url({ #营销网址
  'zh-Hans' => "http://www.baidu.com"
})

privacy_url({
  'zh-Hans' => "http://www.baidu.com"
})

app_icon('./fastlane/metadata/AppIcon.png') #应用图标1024 * 1024

primary_category("Utilities") #类别设置  参考网站https://docs.fastlane.tools/actions/upload_to_app_store/#reference
# primary_first_sub_category "Card"
# primary_second_sub_category "Casino"
# 要设置的次要类别 无
# secondary_category  
# 设置的次要第一个子类别 无
# secondary_first_sub_category  
# 设置的次要第二个子类别 无
# secondary_second_sub_category

automatic_release true #审核过之后自动发布


  • 编辑Fastfile文件,编写打包release版本代码
default_platform(:ios)
platform :ios do
   desc "打包release版本"
# 运行打包命令 fastlane buile_release name:your project name
  lane :buile_release do |options|
    name = options[:name]
    gym(
      clean:true, # 是否清空以前的编译信息 true:是
      scheme: name, # 自己项目名称
      workspace: "#{name}.xcworkspace", # 自己项目名称xcworkspace(使用cocoapods才会生成)
      export_method:"app-store", #app-store,ad-hoc,enterprise,development
      configuration:"Release",
      output_directory:"./fastlane/release_ipa", # 打包后的 ipa 文件存放的目录
      export_xcargs: "-allowProvisioningUpdates", #访问钥匙串
      output_name: "#{name}.ipa",# ipa 文件名
      silent:true, #隐藏没有必要的信息
      include_bitcode: true,
      export_options: {
        provisioningProfiles: {
          "com.you.bundleIdentifier" => "your_appStore" # bundleid,打包用的证书名字,这里也可以采用参数传递,看个人喜好吧
        }
      }
    )
  end


  desc "Upload to App Store"
  lane :upload do |options|
    deliver( #提交App Store审核
      ipa:"./fastlane/release_ipa/#{options[:name]}.ipa", #ipa路径
      force : false, #是否跳过网页审查,上传过程中会形成一个预览界面
      submit_for_review(true) #上传成功后立马提交审核
    ) 
  end

  # 使用方法 fastlane build_upload name:your project name
  desc "build relese ipa and upload to App Store"
  lane :build_upload do |options|
    buile_release(options)
    upload(options) #提交App Store审核
  end
end

  • 使用方法:进入项目工程
fastlane build_upload name:your project name
  • 演示效果
    这里写图片描述

这里写图片描述

问题

由于mac系统更新或者其他原因导致fastlane的问题。

Ignoring gem-wrappers-1.3.2 because its extensions are not built.  Try: gem pristine gem-wrappers --version 1.3.2
Ignoring unf_ext-0.0.7.5 because its extensions are not built.  Try: gem pristine unf_ext --version 0.0.7.5
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems.rb:241:in `bin_path': can't find gem fastlane (>= 0.a) (Gem::GemNotFoundException)
	from /usr/local/bin/fastlane:22:in `<main>'

解决办法:

1、指定默认的ruby版本
rvm use 2.3.7 --default
2、重新安装
brew cask reinstall fastlane
3、然后看控制台信息
Updating installed gems
ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
    bad response Not Found 404 (https://gems.ruby-china.org/specs.4.8.gz)
Cleaning up installed gems...
Clean Up Complete
Detected shell config file at path '~/.bash_profile'
Please add the following line to your bash profile:

export PATH="$HOME/.fastlane/bin:$PATH"

After doing so close the terminal session and restart it to start using fastlane ?
?  fastlane was successfully installed!
-----------------------------
最后在.bash_profile写入环境变量
vim ~/.bash_profile
export PATH="$HOME/.fastlane/bin:$PATH"

企业包Fastfile的配置

利用Fastfile自动打包企业包上传到蒲公英的Fastfile文件编写配置

default_platform(:ios)

platform :ios do
  desc "上传到蒲公英"
    # 运行打包命令 fastlane inhouse_release name:moffice scheme_name:coap
	lane :inhouse_release do |options|
	    name = options[:name]
      	scheme_name = options[:scheme_name] #如果是单target项目可以不配置这个
	    xcode_select "/Applications/Xcode.app"

	    gym(
	      clean:true, # 是否清空以前的编译信息 true:是
	      scheme: scheme_name, # 自己项目名称
	      workspace: "#{name}.xcworkspace", # 自己项目名称xcworkspace(使用cocoapods才会生成)
	      export_method:"enterprise", #app-store,ad-hoc,enterprise,development
	      configuration:"Release", # Release  Debug
	      output_directory:"./fastlane/build", # 打包后的 ipa 文件存放的目录
	      export_xcargs: "-allowProvisioningUpdates", #访问钥匙串
	      output_name: "#{name}.ipa",# ipa 文件名
	      silent:true,#隐藏没有必要的信息

	      export_options: {
	        provisioningProfiles: {
	          "bundleid" => "证书名字" # bundleid,打包用的证书名字
	        }
	      }
	    )

    pgyer(
      api_key: "api_key", 
      user_key: "user_key", 
      password: "123456", # 密码
      update_description: "无"#"description" # 本次测试更新的文字说明(参数设置)
    )
  end
end
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值