需管理员和所属者权限
在 Mac 上生成 CSR 文件:
cd ios && open YourProject.xcworkspace
登录开发者账号,建议登录有管理权限的开发者账号
创建 Provisioning Profile: 开发环境:选择 iOS Development,关联证书和 App ID 生产环境:选择 App Store 或 Ad Hoc
下载 .mobileprovision 文件,双击安装
在 Xcode 中手动选择证书和 Profile: Signing (Debug):开发证书 Signing (Release):生产证书
看能否正常打包开发/生产包
打开 钥匙串访问.app: 进入:应用程序 > 实用工具 > 钥匙串访问
选择左上角: 钥匙串:登录 分类:我的证书
找到你的 Apple 证书(名称类似于 Apple Distribution: 你的公司名)
如果你没看到导出选项,说明这个证书没有关联私钥(你是从别人那里拿的 .cer 而不是用自己的私钥生成的)
推荐方法:
方法 1:通过 Mac 上的 Finder 或 iTunes(macOS Catalina 10.15 及更高版本)
方法 2:通过 Xcode 获取
连接设备到 Mac
打开 Xcode,进入顶部菜单: Window > Devices and Simulators
选择已连接的设备,在右侧信息面板中找到 Identifier(即 UDID) 右键点击 UDID 选择 Copy
将相关证书放到certificate/ios/目录下,记得配置git忽略
development:device ad-hoc分发包 production 正式分发包
{
"cli": {
"version": ">= 3.15.1",
"appVersionSource": "local"
},
"build": {
"development": {
"extends": "production",
"distribution": "internal",
"android": {
"gradleCommand": ":app:assembleDebug"
},
"ios": {
"buildConfiguration": "Debug",
"simulator": true
}
},
"development:device": {
"extends": "development",
"distribution": "internal",
"ios": {
"buildConfiguration": "Release",
"simulator": false,
"credentialsSource": "local"
}
},
"preview": {
"extends": "production",
"distribution": "internal",
"ios": {
"simulator": true
},
"android": {
"buildType": "apk"
}
},
"preview:device": {
"extends": "preview",
"ios": {
"simulator": false
}
},
"production": {
"android": {
"buildType": "apk",
"credentialsSource": "local"
},
"ios": {
"credentialsSource": "local",
"autoIncrement": true
}
}
},
"submit": {
"production": {}
}
}
打不同(开发/生产)iOS包,选择不同的证书
证书和描述文件对照关系
打包测试分发包,使用如下对照文件
ios_distribution.p12 - adhoc.mobileprovision
打包正式分发包,使用如下对照文件
ios_distribution.p12 - prod.mobileprovision
{
"android": {
"keystore": {
"keystorePath": "./certificate/keystore.jks",
"keystorePassword": "xinyun2024",
"keyAlias": "cjxy",
"keyPassword": "xinyun2024"
}
},
"ios": {
"provisioningProfilePath": "certificate/ios/profile.mobileprovision",
"distributionCertificate": {
"path": "certificate/ios/dist.p12",
"password": "DISTRIBUTION_CERTIFICATE_PASSWORD"
}
}
}
使用本地证书,不需要此步骤
安装 Fastlane
# 使用 RubyGems 安装(需 Ruby 环境)
gem install fastlane -NV
# 或通过 Homebrew(macOS)
brew install fastlane
验证安装
fastlane --version
初始化 Fastlane
cd ios && fastlane init
配置 Fastlane
lane :build_for_eas do
setup_ci
sync_code_signing(type: "appstore") # 如果是 App Store 分发
# 或其他自定义步骤
end
# 查看描述文件SHA1
security cms -D -i xyapp_dev.mobileprovision > profile.plist
plutil -extract DeveloperCertificates.0 xml1 profile.plist -o - | \
awk '/<data>/{flag=1;next}/<\/data>/{flag=0}flag' | \
tr -d '\n ' | base64 -d > cert.der
openssl x509 -inform DER -in cert.der -noout -fingerprint
> SHA1 Fingerprint=A9:EE:A8:00:24:3F:DF:9F:57:B9:84:83:13:F4:A1:C6:55:E2:DD:DB
# 查看p12文件SHA1
openssl pkcs12 -in ios_development.p12 -nokeys -nodes -legacy -out cert.pem
openssl x509 -in cert.pem -noout -fingerprint
> SHA1 Fingerprint=A9:EE:A8:00:24:3F:DF:9F:57:B9:84:83:13:F4:A1:C6:55:E2:DD:DB