说明
具体的Fastlane安装使用我这里就不多说了 网上一大片文档 只记录一下使用时候遇到场景的想法和解决方式
官方文档:Fastlane Docs
场景
我们项目一般是分企业包和非企业包 一个(企业证书)负责分发 一个是供指定设备安装测试
一般常见有两种处理方式:
A、添加不同多targets 区分企业包和开发包identifier 和证书或一些配置项 在打包时选择一个target去打包就可以 如图:多个target
这种方式使用fastlane打包可以参考Fastlane 实现多 Target 自动化打包发布这篇文章
B、项目中只维护一个主target 同时添加了一些Service Extension(如上图 添加了widget、watch、notification 等extension)
在使用fastlane打包时 我们考虑到企业包和非企业包的bundle identifier 和 sign certificate 不一样 我们暂时又不打算以分仓库或再在项目中加一次targets来区分企业包(如A)
所以想到脚本的方式去改变bundle id 和sign cer 替换为企业包的一些配置包括改target extension 的配置 这样可以达到一个项目可以一键分别打企业包和非企业包测试 抱着这个想法查了一遍官方文档 发现是有这个指令automatic_code_signing
Key | Description | Default |
---|---|---|
path |
Path to your Xcode project | * |
use_automatic_signing |
Defines if project should use automatic signing | false |
team_id |
Team ID, is used when upgrading project | |
targets |
Specify targets you want to toggle the signing mech. (default to all targets) | |
code_sign_identity |
Code signing identity type (iPhone Developer, iPhone Distribution) | |
profile_name |
Provisioning profile name to use for code signing | |
profile_uuid |
Provisioning profile UUID to use for code signing | |
bundle_identifier |
Application Product Bundle Identifier |
但发现好像并不能满足我们的需求 每个targets extension的bundle identifier是独立的
所以经过我们测试找到了这个方法update_app_identifier
Code Example
Update an app identifier by either setting CFBundleIdentifier or PRODUCT_BUNDLE_IDENTIFIER, depending on which is already in use.
update_app_identifier(
xcodeproj: "Example.xcodeproj", # Optional path to xcodeproj, will use the first .xcodeproj if not set
plist_path: "Example/Info.plist", # Path to info plist file, relative to xcodeproj
app_identifier: "com.test.example" # The App Identifier
)
处理多个target extension
platform :ios do
desc "打包企业版 更改项目和扩展bundle id"
lane :test do
update_app_identifier(
xcodeproj: "testApp.xcodeproj",
app_identifier: "com.testApp.testAppPublic",
plist_path: "testApp/Supporting\ Files/Info.plist",
)
update_app_identifier(
app_identifier: "com.testApp.testAppPublic.Extension",
plist_path: "testAppExtension/Supporting\ Files/Info.plist",
)
.........
automatic_code_signing(
use_automatic_signing: true,
team_id: "xxxxxxx",
)
其实也是实现了一个lane的脚本函数 每个Extension都配置执行一次update_app_identifier
来更新bundle identifier 和 plist_path
当然你也可以自己写脚本去改.xcodeproj的配置项来做更多的更改