fastlane 自动化03----构建、编译

传送门:

fastlane 自动化01----初识
fastlane 自动化02----证书签名
fastlane 自动化03----构建、编译
fastlane 自动化04----分发、上传(未完待续。。。)

先看一下官方给 的codesign相关的有哪些action.

Action Description Supported Platforms
gym Alias for the build_ios_app action ios, mac
cocoapods Runs pod install for the project ios, mac
gradle All gradle related actions, including building and testing your Android app ios, android
clear_derived_data Deletes the Xcode Derived Data ios, mac
adb Run ADB Actions android
xcversion Select an Xcode to use by version specifier ios, mac
xcodebuild Use the xcodebuild command to build and sign your app ios, mac
carthage Runs carthage for your project ios, mac
xcode_select Change the xcode-path to use. Useful for beta versions of Xcode ios, mac
ensure_xcode_version Ensure the right version of Xcode is used ios, mac
clean_cocoapods_cache Remove the cache for pods ios, mac
verify_xcode Verifies that the Xcode installation is properly signed by Apple ios, mac
xcode_install Make sure a certain version of Xcode is installed ios, mac
verify_pod_keys Verifies all keys referenced from the Podfile are non-empty ios, mac
xcclean Cleans the project using xcodebuild ios, mac
build_android_app Alias for the gradle action ios, android
xcexport Exports the project using xcodebuild ios, mac
xcarchive Archives the project using xcodebuild ios, mac
build_app Alias for the build_ios_app action ios, mac
build_ios_app Easily build and sign your app (via gym) ios, mac
xctest Runs tests on the given simulator ios, mac
xcbuild Builds the project using xcodebuild ios, mac
spm Runs Swift Package Manager on your project ios, android, mac

好了,知道你也不想看,其实这里面最重要也就是那个gymcocoapodscocoapods比较简单,用来在签名前先把pods上的三方库拉到本地,gym就是用来构建和签名app用的,他的功能最为丰富.

Action具体用法
1.cocoapods三方库管理工具

先来看看cocoapods有哪些参数

#查看cocoapods有哪些参数
$ fastlane action cocoapods 

use the cocoapods integration to run pod install before building your app.
所以这个action的作用就是pod install

Key Description Default
repo_update 相当于 pod install --repo-update命令
clean_install 忽略本地缓存 (PS:我测试时,该参数不能被识别,先用废弃的clean参数代替) false
silent 静默执行 false
verbose 详细输出 false
ansi 允许终端输出展示富文本(如输入不同颜色、背景的文字) true
use_bundle_exec 有gemfile文件则执行命令为: bundle exec + your_command,如$ bundle exec fastlane action cocoapods true
podfile 设置fastlane文件夹相对包含podfile文件夹的相对路径
error_callback 出错后回调
try_repo_update_on_error 当失败后,尝试更新索引 false
deployment install期间忽略podfile的更改 false

eg.

  cocoapods(
    podfile:"./", #此时podfile和fastlane文件夹在同一目录下
    verbose: true,
    clean: "true",
  )
2.gym 编译构建签名

老规矩,先来看看gym有哪些参数:

$ fastlane action gym

Parameters

Key Description Default
workspace 🔺 Path to the workspace file
project🔺 Path to the project file
scheme🔺 The project's scheme. Make sure it's marked as Shared,注意一定要在mange scheme中设置shared 为勾选状态
clean Should the project be cleaned before building it? false
output_directory 🔺 The directory in which the ipa file should be stored in .
output_name🔺 The name of the resulting ipa file
configuration🔺 The configuration to use when building the app. Defaults to 'Release' *
silent Hide all information that's not necessary while building false
codesigning_identity The name of the code signing identity to use. It has to match the name exactly. e.g. 'iPhone Distribution: SunApps GmbH'
skip_package_ipa Should we skip packaging the ipa? false
include_symbols Should the ipa file include symbols?
include_bitcode🔺 Should the ipa file include bitcode?
export_method🔺 Method used to export the archive. Valid values are: app-store, ad-hoc, package, enterprise, development, developer-id
export_options 🔺 Path to an export options plist or a hash with export options. Use 'xcodebuild -help' to print the full set of available options
export_xcargs 测试无用,可以用xcargs来代替,Pass additional arguments to xcodebuild for the package phase. Be sure to quote the setting names and values e.g. OTHER_LDFLAGS="-ObjC -lstdc++"
skip_build_archive Export ipa from previously built xcarchive. Uses archive_path as source
skip_archive After building, don't archive, effectively not including -archivePath param
skip_codesigning Build without codesigning
build_path The directory in which the archive should be stored in
archive_path The path to the created archive
derived_data_path The directory where built products and other derived data will go
result_bundle Should an Xcode result bundle be generated in the output directory false
result_bundle_path Path to the result bundle directory to create. Ignored if result_bundle if false
buildlog_path The directory where to store the build log *
sdk The SDK that should be used for building the application
toolchain The toolchain that should be used for building the application (e.g. com.apple.dt.toolchain.Swift_2_3, org.swift.30p620160816a)
destination Use a custom destination for building the app
export_team_id Optional: Sometimes you need to specify a team id when exporting the ipa file
xcargs🔺 Pass additional arguments to xcodebuild for the build phase. Be sure to quote the setting names and values e.g. OTHER_LDFLAGS="-ObjC -lstdc++"
xcconfig Use an extra XCCONFIG file to build your app
suppress_xcode_output Suppress the output of xcodebuild to stdout. Output is still saved in buildlog_path
disable_xcpretty Disable xcpretty formatting of build output
xcpretty_test_format Use the test (RSpec style) format for build output
xcpretty_formatter A custom xcpretty formatter to use
xcpretty_report_junit Have xcpretty create a JUnit-style XML report at the provided path
xcpretty_report_html Have xcpretty create a simple HTML report at the provided path
xcpretty_report_json Have xcpretty create a JSON compilation database at the provided path
analyze_build_time Analyze the project build time and store the output in 'culprits.txt' file
xcpretty_utf Have xcpretty use unicode encoding when reporting builds
skip_profile_detection Do not try to build a profile mapping from the xcodeproj. Match or a manually provided mapping should be used false

上面参数,常用的我已经用🔺标明。其中workspaceproject只需要设置其中任何一个即可,否则打包过程会报错,这里重点说一下export_optionsxcargs.

  • export_options

这个是xcodebuild命令的可用选项,可以在终端中用$ xcodebuild -help来查看相关命令,当你的fastlane中没有使用match 配合gym打包时,可以指定一个hash map来决定使用的那个证书来签名,如:

    export_options: {
        compileBitcode: false,
        provisioningProfiles: {
          "com.LSJ.Fastlane" => "match Development com.LSJ.Fastlane", 
       }
    }
// hashmap的 key为bundleID,value为对应的provison profile
  • xcargs

这个也是在执行xcodebuild命令的时添加参数。比如生活Debug模式添加几宏DEBUG=1 TEST=1,设置OTHER_LDFLAGS="-ObjC -lstdc++ 等等...类似于如下结构:

    xcargs: {
        :GCC_PREPROCESSOR_DEFINITIONS => "DEBUG=1 TEST=1", #设置宏定义
        :OTHER_LDFLAGS => "-ObjC -lstdc++" #设置link flags
    },

像上面的OTHER_LDFLAGS"-ObjC -lstdc++"这种xcargs参数key和value如何确定呢?

当我们在工程的build setting里设置了other link Flags相关参数,如下图


这时工程就会生成对应的字段去记录。打开XXXX.xcproject文件所在的目录,右击XXXX.xcproject => 显示包内容 => 打开project.pbxproj,这个project.pbxproj就是来记录工程设置的文件,
打开文件后搜索你设置的value值,如-Objc,然后定位到相关位置如下图:

other link Flagsxcodebuild 命令中的参数值就是OTHER_LDFLAGS,如果value值有多个数值,则中间通过空格分隔开,所以是 OTHER_LDFLAGS => "-Objc -lstdc++".

上代码:

 gym(
    workspace: "AutoUploadProject.xcworkspace", 
    configuration: "Debug", #Debug Release DailyBuild 编译环境
    export_method: "development", #用development开发证书签名
    #project: "AutoUploadProject.xcodeproj", 
    scheme: "AutoUploadProject", #必须勾选为shared
    clean: true,  //每次编译前先clean
    export_xcargs: "-allowProvisioningUpdates", #允许访问证书
    output_name: "my-app.ipa", #输出名称
    xcargs: {
        :GCC_PREPROCESSOR_DEFINITIONS => other_flags,
        #"GCC_PREPROCESSOR_DEFINITIONS" => "DEBUG=1 TEST=1"
    },
    #export_team_id: "66L654578N", #teamID在生产、测试证书中是不同的。
    #export_xcargs: "GCC_PREPROCESSOR_DEFINITIONS='MYCODE'",
    export_options: {
        compileBitcode: false,
       # provisioningProfiles: {
       #     "com.LSJ.Fastlane" => "match Development com.LSJ.Fastlane",
       # } #如果跟`match`连用,则不用设置设置bundleID=>provision profiles的对应关系。
    }
  )
  end
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,657评论 6 505
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,889评论 3 394
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,057评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,509评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,562评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,443评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,251评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,129评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,561评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,779评论 3 335
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,902评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,621评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,220评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,838评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,971评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,025评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,843评论 2 354

推荐阅读更多精彩内容