傳送門:
fastlane 自動(dòng)化01----初識(shí)
fastlane 自動(dòng)化02----證書簽名
fastlane 自動(dòng)化03----構(gòu)建择葡、編譯
fastlane 自動(dòng)化04----分發(fā)、上傳(未完待續(xù)函匕。千诬。耍目。)
先看一下官方給 的codesign相關(guān)的有哪些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 |
好了,知道你也不想看徐绑,其實(shí)這里面最重要也就是那個(gè)gym
和cocoapods
制妄。cocoapods
比較簡(jiǎn)單,用來(lái)在簽名前先把pods上的三方庫(kù)拉到本地泵三,gym
就是用來(lái)構(gòu)建和簽名app用的,他的功能最為豐富.
Action具體用法
1.cocoapods
三方庫(kù)管理工具
先來(lái)看看cocoapods有哪些參數(shù)
#查看cocoapods有哪些參數(shù)
$ fastlane action cocoapods
use the
cocoapods
integration to runpod install
before building your app.
所以這個(gè)action的作用就是pod install
衔掸。
Key | Description | Default |
---|---|---|
repo_update | 相當(dāng)于 pod install --repo-update 命令 |
|
clean_install | 忽略本地緩存 (PS:我測(cè)試時(shí)烫幕,該參數(shù)不能被識(shí)別,先用廢棄的clean 參數(shù)代替) |
false |
silent | 靜默執(zhí)行 | false |
verbose | 詳細(xì)輸出 | false |
ansi | 允許終端輸出展示富文本(如輸入不同顏色敞映、背景的文字) | true |
use_bundle_exec | 有g(shù)emfile文件則執(zhí)行命令為: bundle exec + your_command较曼,如$ bundle exec fastlane action cocoapods
|
true |
podfile | 設(shè)置fastlane文件夾相對(duì)包含podfile文件夾的相對(duì)路徑 | |
error_callback | 出錯(cuò)后回調(diào) | |
try_repo_update_on_error | 當(dāng)失敗后,嘗試更新索引 | false |
deployment | install期間忽略podfile的更改 | false |
eg.
cocoapods(
podfile:"./", #此時(shí)podfile和fastlane文件夾在同一目錄下
verbose: true,
clean: "true",
)
2.gym
編譯構(gòu)建簽名
老規(guī)矩振愿,先來(lái)看看gym有哪些參數(shù):
$ 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中設(shè)置shared 為勾選狀態(tài) |
|
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 |
測(cè)試無(wú)用弛饭,可以用xcargs 來(lái)代替,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 |
上面參數(shù),常用的我已經(jīng)用??標(biāo)明萍歉。其中workspace
侣颂、project
只需要設(shè)置其中任何一個(gè)即可,否則打包過(guò)程會(huì)報(bào)錯(cuò)枪孩,這里重點(diǎn)說(shuō)一下export_options
和xcargs
.
-
export_options
這個(gè)是xcodebuild
命令的可用選項(xiàng)憔晒,可以在終端中用$ xcodebuild -help
來(lái)查看相關(guān)命令,當(dāng)你的fastlane中沒(méi)有使用match
配合gym
打包時(shí)蔑舞,可以指定一個(gè)hash map來(lái)決定使用的那個(gè)證書來(lái)簽名拒担,如:
export_options: {
compileBitcode: false,
provisioningProfiles: {
"com.LSJ.Fastlane" => "match Development com.LSJ.Fastlane",
}
}
// hashmap的 key為bundleID,value為對(duì)應(yīng)的provison profile
-
xcargs
這個(gè)也是在執(zhí)行xcodebuild
命令的時(shí)添加參數(shù)攻询。比如生活Debug模式添加幾宏DEBUG=1 TEST=1
从撼,設(shè)置OTHER_LDFLAGS="-ObjC -lstdc++
等等...類似于如下結(jié)構(gòu):
xcargs: {
:GCC_PREPROCESSOR_DEFINITIONS => "DEBUG=1 TEST=1", #設(shè)置宏定義
:OTHER_LDFLAGS => "-ObjC -lstdc++" #設(shè)置link flags
},
像上面的OTHER_LDFLAGS
和 "-ObjC -lstdc++"
這種xcargs參數(shù)key和value如何確定呢?
當(dāng)我們?cè)诠こ痰腷uild setting里設(shè)置了other link Flags
相關(guān)參數(shù)钧栖,如下圖
這時(shí)工程就會(huì)生成對(duì)應(yīng)的字段去記錄低零。打開
XXXX.xcproject
文件所在的目錄,右擊XXXX.xcproject
=> 顯示包內(nèi)容 => 打開project.pbxproj
,這個(gè)project.pbxproj
就是來(lái)記錄工程設(shè)置的文件桐经,打開文件后搜索你設(shè)置的value值毁兆,如
-Objc
,然后定位到相關(guān)位置如下圖:那
other link Flags
在xcodebuild
命令中的參數(shù)值就是OTHER_LDFLAGS
阴挣,如果value值有多個(gè)數(shù)值气堕,則中間通過(guò)空格分隔開,所以是 OTHER_LDFLAGS => "-Objc -lstdc++"
.
上代碼:
gym(
workspace: "AutoUploadProject.xcworkspace",
configuration: "Debug", #Debug Release DailyBuild 編譯環(huán)境
export_method: "development", #用development開發(fā)證書簽名
#project: "AutoUploadProject.xcodeproj",
scheme: "AutoUploadProject", #必須勾選為shared
clean: true, //每次編譯前先clean
export_xcargs: "-allowProvisioningUpdates", #允許訪問(wèn)證書
output_name: "my-app.ipa", #輸出名稱
xcargs: {
:GCC_PREPROCESSOR_DEFINITIONS => other_flags,
#"GCC_PREPROCESSOR_DEFINITIONS" => "DEBUG=1 TEST=1"
},
#export_team_id: "66L654578N", #teamID在生產(chǎn)畔咧、測(cè)試證書中是不同的茎芭。
#export_xcargs: "GCC_PREPROCESSOR_DEFINITIONS='MYCODE'",
export_options: {
compileBitcode: false,
# provisioningProfiles: {
# "com.LSJ.Fastlane" => "match Development com.LSJ.Fastlane",
# } #如果跟`match`連用,則不用設(shè)置設(shè)置bundleID=>provision profiles的對(duì)應(yīng)關(guān)系誓沸。
}
)
end