美文网首页
使用fastlane的踩坑记录

使用fastlane的踩坑记录

作者: 滚来滚去的桔子 | 来源:发表于2019-02-13 16:47 被阅读2次

本来是想用jenkins+xcode的,但是jenkins一直构建不成功,问题一个接一个,最后先放弃,小项目就单用fastlane了。

1、首先是安装的时候,用了homebrew安装 brew cask install fastlane ,报错了error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54 这个的解决倒是比较简单,就是下东西的时候缓存空间不够,命令行输入下面这句就ok了。

git config --global http.postBuffer 524288000

2、然后cd 到项目目录,开始fastlane init,报错/Applications/Xcode.app....什么之类的,报错信息的路径不一定,总之是没找到xcode。两种方法:

1.在终端中使用 xcode-select -print-path 打印命令查看xcode安装位置
2.更改xcode位置:sudo ./xcode-select -switch  想要的路径  
3.再次使用 xode-select -print-path ,已经显示新的路径了

或者打开 /Users/你的电脑账户名/.bash_profile 文件,把下面这句加进去

export DEVELOPER_DIR="电脑上xcode的真实路径"  
// 比如我的是/Applications/Xcode.app/Contents/Developer
// 路径可以利用终端得到:找到xcode,按住图标往终端窗口里拖 

建议是2种都用,避免今后与此有关的问题出现。还有个在bundle update 卡很久的问题,下面的一起解决了。

3、接着fastlane add_plugin pgyer 打算安装蒲公英的插件。然后各种花式报错,gem source(已经改成淘宝镜像了还是报错--找到问题了,最后说) 、bundle相关的、文件读写权限问题等等。花了好长时间,终于是搞定了。首先gem source一定要是http://gems.ruby-china.com/,然后来安装bundler。为了以后都省事点,使用Homebrew另外安装了个gem (brew gem还是brew install gem来着),然后

gem install bundler
cd 使用fastlane的目录
bundle install    // 这里安装了一大堆包
fastlane add_plugin pgyer   // OK,终于装上蒲公英的插件了。

因为系统自己带的gem,安装其他东西需要改动文件的时候,经常会没有权限(/usr/bin的写权限,各种方法都加不进去)。有时候可以用sudo,或者加命令参数,或者可以改gem的配置去解决,但还是觉得另外用一个方便很多。

最后在 fastlane/Fastfile 文件里好好写上各种构建、打包、发布的配置,下面是我的demo。

default_platform(:ios)

platform :ios do
desc "上传蒲公英测试"
  desc "生成本地版本"
  lane :testpgyer do|option|

    #定义一些变量,后面用
    # 项目名称
    scheme_name = "要打包的项目名称"

    #获取version和build版本号
    version = get_info_plist_value(path: "./#{scheme_name}/Info.plist", key: "CFBundleShortVersionString")
    build = get_info_plist_value(path: "./#{scheme_name}/Info.plist", key: "CFBundleVersion")

    #导出路径 文件夹没有的话会自动新建一个
    output_directory = "./build"   

    #导出名称
    output_name = "#{scheme_name}_#{version}_#{build}_#{option[:desc]}_#{Time.now.strftime('%Y%m%d%H%M%S')}.ipa"

    gym(
      export_method: "ad-hoc",     #导出方式
      export_xcargs: "-allowProvisioningUpdates",
      include_bitcode: false,
      scheme: scheme_name,
      clean: true,
      output_directory: output_directory,
      output_name: output_name
     )

    pgyer(api_key: "xxxx", user_key: "xxxx", update_description: "#{option[:desc]}")
end
end

命令行跑fastlane testpgyer desc:测试,搞定。

最后说说gem source的问题。现象是:使用fastlane相关命令时,经常会提示要执行fastlane update_fastlane更新,并且出现报错信息:

提示source源不正确
咱的source早就是http://gems.ruby-china.com/了,为什么还有这种提示?原因在于Gemfile文件,这是fastlane的依赖管理文件,打开一看,第一行就是source "https://rubygems.org",明白了吧?改掉就好了。

打包(gym)相关的参数可以在fastlane的文档看。

相关文章

网友评论

      本文标题:使用fastlane的踩坑记录

      本文链接:https://www.haomeiwen.com/subject/spfdeqtx.html