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

你可能感兴趣的:(fastlane 自动化03----构建、编译)