ARTICLE DETAIL

资讯详情

深耕郑州网站建设与运营推广的一线实战洞察。

fastlane 如何用 cert 和 sigh 自动生成 iOS 代码签名证书与 Provisioning Profile

fastlane 如何用 cert 和 sigh 自动生成 iOS 代码签名证书与 Provisioning Profile fastlane 如何用 cert 和 sigh 自动生成 iOS 代码签名证书与 Provisioning Profile【免费下载链接】fastlane The easiest way to automate building and releasing your iOS and Android apps项目地址: https://gitcode.com/GitHub_Trending/fa/fastlane当你要把 iOS 应用的构建放进 CI 或自动化脚本时代码签名证书和 Provisioning Profile 是绕不开的两个文件证书过期、Profile 失效都会让打包直接失败。fastlane 提供cert和sigh两个动作来分别解决这两件事——cert负责创建并安装代码签名证书sigh负责创建、续期、下载并修复 Provisioning Profile。本文说明如何用这两个动作完成“证书 Profile”的自动化生成以及每一步如何确认结果。适用前提拥有 Apple Developer Portal开发者门户账号证书创建需要 Team Admin 权限才能创建 Distribution 证书建议运行环境为 macOScert会在 macOS 上把证书导入 Keychain 并做本地安装校验非 macOS 系统上这两步会被跳过keychain_path、keychain_password等参数也不支持登录方式二选一Apple ID 账号密码fastlane 的 CredentialsManager 负责管理或 App Store Connect API Key。准备配置 Appfilecert和sigh都优先从Appfile读取应用的 bundle identifier 与 Apple ID无需每次都传参数。仓库中的 Appfile 模板AppfileTemplate展示了最小配置app_identifier(com.example.app) # 你的 App bundle identifier apple_id(youexample.com) # Apple Developer Portal 用户名如果在多个团队之间切换还可以配置 team_id / team_name对应cert、sigh的team_id、team_name参数。确认某个动作支持哪些参数和环境变量可以直接运行fastlane action cert fastlane action sigh第一步用 cert 生成并安装签名证书最基本的命令是fastlane certsigh/cert的文档明确指出在 fastlane 中cert是get_certificates的别名sigh是get_provisioning_profile的别名见 get_certificates 文档、get_provisioning_profile 文档。cert的执行逻辑由 Runner 实现 决定是先检查本地机器上是否已安装可用的签名证书已存在则直接复用只有在需要新建证书时才会创建新的私钥、创建证书签名请求CSR、向 Apple 请求生成证书下载并安装到本地 Keychain。如果 Appfile 中没写apple_id可以在命令行直接传入 Apple IDfastlane cert -u certexample.com常用参数均可通过fastlane action cert查看也支持对应环境变量如CERT_DEVELOPMENT、CERT_OUTPUT_PATHdevelopment: true创建 Development 证书而不是默认的 Distribution 证书generate_apple_certs创建 Xcode 11 及以上使用的 Apple Development / Apple Distribution 证书macOS Xcode 11 环境下默认为truetype:指定特殊证书类型取值mac_installer_distribution、developer_id_installer、developer_id_application、developer_id_kextoutput_path-o证书和私钥文件的保存目录默认.keychain_path、keychain_password自定义 Keychain 及其密码仅 macOS。执行后如何确认成功在 macOS 上终端会输出 “Verifying the certificate is properly installed locally...”成功后显示Successfully installed certificate 证书ID如果在 Keychain 中找不到新证书会直接报错退出证书文件被写入output_path默认为当前目录同时在 lane 中产生两个共享值CERT_FILE_PATH证书文件路径和CERT_CERTIFICATE_ID证书 ID非 macOS 环境会提示 “Skipping verifying certificates...”只生成证书文件而不做本地安装。一个需要知道的边界cert永远不会撤销你已有的证书。当证书数量达到 Apple 的上限时cert会抛出异常需要你先在开发者门户手动撤销旧证书才能腾出名额。第二步用 sigh 生成 Provisioning Profilesigh默认针对 App Store 类型执行“创建、修复、下载”Profile 的完整流程fastlane sigh指定 bundle identifier 和 Apple ID 的完整写法fastlane sigh -a com.example.app -u youexample.com按目标用途选择 Profile 类型三类参数互斥不能同时开启fastlane sigh # 默认 App Store fastlane sigh --adhoc # Ad Hoc fastlane sigh --development # Development与cert配合时最关键的几个参数-ooutput_pathProfile 保存目录默认当前目录。例如fastlane sigh -o ~/Certificates/force-f无论现有 Profile 状态如何都重新生成得到最长有效期的 Profile并且会把所有可用设备加进 Profile-qfilename指定生成的 Profile 文件名必须以.mobileprovision结尾例如fastlane sigh -a com.example.app -u youexample.com -q myProfile.mobileprovision--skip_install只生成 Profile 文件不安装到本地-ccert_owner_name指定新 Profile 使用哪张证书例如fastlane sigh -c SunApps GmbH。关于证书选择有一条明确的联动规则如果同一个 fastlane lane 中先运行了certsigh会自动使用cert刚生成的签名证书cert会把证书 ID 写入SIGH_CERTIFICATE_ID供sigh使用不需要再用-c手动指定。执行成功后Profile 文件.mobileprovision落在output_path指定的目录lane 中可以得到SIGH_PROFILE_PATH本次 Profile 的绝对路径、SIGH_UUID、SIGH_NAME等共享值供后续动作如构建、上传直接使用。组合到 Fastfile一条 lane 完成证书和 Profilecert和sigh官方推荐的用法是在同一个 lane 中串联。在Fastfile中写入lane :beta do cert sigh(force: true) end然后用fastlane beta触发。这里force: true的作用是每次都重新生成 Provisioning Profile保证sigh始终使用本地机器上刚由cert安装的那张签名证书。已知限制与注意事项文档明确建议对于大多数项目更推荐用 fastlane 的match方案统一生成和维护证书与 Profile直接组合certsigh适合想完全掌控签名流程、并熟悉代码签名的场景cert无法从 Apple 开发者门户下载“已有证书的私钥”——私钥永远只存在于当初创建证书的机器上这也是sigh依赖本地 Keychain 中证书的前提sigh使用环境变量SIGH_CERTIFICATE或-c指定证书时也可以传证书名称或过期日期如果sigh提示找不到 App Identifier说明开发者门户里还没有这个 bundle id需要先创建应用标识文档指出的对应动作是producesigh不会触碰 Xcode 自己管理的 Profile它只管理自己生成和下载的那一套。完成fastlane beta或分别运行fastlane cert和fastlane sigh后你的工作目录中应能看到新生成的.cer证书文件与.mobileprovisionProfile 文件终端出现 “Successfully installed certificate” 即为整条链路跑通的标志。【免费下载链接】fastlane The easiest way to automate building and releasing your iOS and Android apps项目地址: https://gitcode.com/GitHub_Trending/fa/fastlane创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表