如何通过 fastlane match 重用苹果证书

how to reuse the apple certificate with fastlane match

因为个人开发者只能有3个分发证书(https://help.apple.com/xcode/mac/current/#/dev3a05256b8),我有3个以上的应用,所以我必须让不同的应用使用相同的证书,这就是我想要做的.

第 1 步:从钥匙串导出证书

第 2 步:使用此命令生成证书文件和 pem 文件:

openssl pkcs12 -nocerts -nodes -out key.pem -in Certificates.p12
openssl aes-256-cbc -k 225843 -in key.pem -out MLD9L5TNVK.p12 -a
openssl aes-256-cbc -k 225843 -in Certificates.cer -out MLD9L5TNVK.cer -a

然后将 MLD9L5TNVK.p12MLD9L5TNVK.cer 文件添加到 fastlane 管理匹配的证书库中。

第 3 步:使用 fastlane 匹配生成配置文件:

fastlane match adhoc

但是当我使用此命令在 GitHub 操作中发布 ios 包时:

  - name: Deploy to TestFlight/PGY
    run: |
      cd ./ios
      bundle exec fastlane beta
    env:
      FLUTTER_ROOT: ${{ secrets.FLUTTER_ROOT }}
      APPLE_ID: ${{ secrets.APPLE_ID }}
      GIT_URL: ${{ secrets.GIT_URL }}
      PGY_USER_KEY: ${{ secrets.PGY_USER_KEY }}
      PGY_API_KEY: ${{ secrets.PGY_API_KEY }}
      TEAM_ID: ${{ secrets.TEAM_ID }}
      ITC_TEAM_ID: ${{ secrets.ITC_TEAM_ID }}
      FASTLANE_USER: ${{ secrets.FASTLANE_USER }}
      FASTLANE_PASSWORD: ${{ secrets.FASTLANE_PASSWORD }}
      FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD: ${{ secrets.FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD }}
      FASTLANE_SESSION: ${{ secrets.FASTLANE_SESSION }}
      MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }}
      MATCH_KEYCHAIN_NAME: ${{ secrets.MATCH_KEYCHAIN_NAME }}
      MATCH_KEYCHAIN_PASSWORD: ${{ secrets.MATCH_KEYCHAIN_PASSWORD }}

显示此错误消息:

No signing certificate "iOS Distribution" found: No "iOS Distribution" signing certificate matching team ID "***" with a private key was found. (in target 'Runner' from project 'Runner')

这是详细日志输出:

+-----------------------------------------------------------+-----------------------------------------------------------+
|                                                Summary for gym 2.191.0                                                |
+-----------------------------------------------------------+-----------------------------------------------------------+
| workspace                                                 | Runner.xcworkspace                                        |
| scheme                                                    | Runner                                                    |
| export_method                                             | ad-hoc                                                    |
| export_options.provisioningProfiles.com.reddwarf.musicapp | match AdHoc com.reddwarf.musicapp 1629273389              |
| clean                                                     | false                                                     |
| output_directory                                          | .                                                         |
| output_name                                               | Runner                                                    |
| silent                                                    | false                                                     |
| skip_package_ipa                                          | false                                                     |
| skip_package_pkg                                          | false                                                     |
| build_path                                                | /Users/runner/Library/Developer/Xcode/Archives/2021-08-18 |
| result_bundle                                             | false                                                     |
| buildlog_path                                             | ~/Library/Logs/gym                                        |
| destination                                               | generic/platform=iOS                                      |
| skip_profile_detection                                    | false                                                     |
| skip_package_dependencies_resolution                      | false                                                     |
| disable_package_automatic_updates                         | false                                                     |
| use_system_scm                                            | false                                                     |
| xcode_path                                                | /Applications/Xcode_12.4.app                              |
+-----------------------------------------------------------+-----------------------------------------------------------+

[10:05:55]: $ set -o pipefail && xcodebuild -workspace Runner.xcworkspace -scheme Runner -destination 'generic/platform=iOS' -archivePath /Users/runner/Library/Developer/Xcode/Archives/2021-08-18/Runner\ 2021-08-18\ 10.05.55.xcarchive archive | tee /Users/runner/Library/Logs/gym/Runner-Runner.log | xcpretty
[10:06:00]: ▸ ❌  error: No signing certificate "iOS Distribution" found: No "iOS Distribution" signing certificate matching team ID "***" with a private key was found. (in target 'Runner' from project 'Runner')
[10:06:00]: ▸     The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.4.99. (in target 'Flutter' from project 'Pods')
[10:06:00]: ▸ ** ARCHIVE FAILED **

❌  error: No signing certificate "iOS Distribution" found: No "iOS Distribution" signing certificate matching team ID "***" with a private key was found. (in target 'Runner' from project 'Runner')


    The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.4.99. (in target 'Flutter' from project 'Pods')
** ARCHIVE FAILED **
[10:06:00]: Exit status: 65
[10:06:00]: 
[10:06:00]: Maybe the error shown is caused by using the wrong version of Xcode
[10:06:00]: Found multiple versions of Xcode in '/Applications/'
[10:06:00]: Make sure you selected the right version for your project
[10:06:00]: This build process was executed using '/Applications/Xcode_12.4.app'
[10:06:00]: If you want to update your Xcode path, either
[10:06:00]: 
[10:06:00]: - Specify the Xcode version in your Fastfile
[10:06:00]: ▸ xcversion(version: "8.1") # Selects Xcode 8.1.0
[10:06:00]: 
[10:06:00]: - Specify an absolute path to your Xcode installation in your Fastfile
[10:06:00]: ▸ xcode_select "/Applications/Xcode8.app"
[10:06:00]: 
[10:06:00]: - Manually update the path using
[10:06:00]: ▸ sudo xcode-select -s /Applications/Xcode.app
[10:06:00]: 

+---------------+------------------------------+
|              Build environment               |
+---------------+------------------------------+
| xcode_path    | /Applications/Xcode_12.4.app |
| gym_version   | 2.191.0                      |
| export_method | ad-hoc                       |
| sdk           | iPhoneOS14.4.sdk             |
+---------------+------------------------------+

[10:06:00]: ▸ note: Building targets in parallel
[10:06:00]: ▸ note: Planning build
[10:06:00]: ▸ note: Constructing build description
[10:06:00]: ▸ error: No signing certificate "iOS Distribution" found: No "iOS Distribution" signing certificate matching team ID "***" with a private key was found. (in target 'Runner' from project 'Runner')
[10:06:00]: ▸ warning: The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.4.99. (in target 'Flutter' from project 'Pods')
[10:06:00]: 
[10:06:00]: ⬆️  Check out the few lines of raw `xcodebuild` output above for potential hints on how to solve this error
[10:06:00]:   For the complete and more detailed error log, check the full log at:
[10:06:00]:   /Users/runner/Library/Logs/gym/Runner-Runner.log
[10:06:00]: 
[10:06:00]: Looks like fastlane ran into a build/archive error with your project
[10:06:00]: It's hard to tell what's causing the error, so we wrote some guides on how
[10:06:00]: to troubleshoot build and signing issues: https://docs.fastlane.tools/codesigning/getting-started/
[10:06:00]: Before submitting an issue on GitHub, please follow the guide above and make
[10:06:00]: sure your project is set up correctly.
[10:06:00]: fastlane uses `xcodebuild` commands to generate your binary, you can see the
[10:06:00]: the full commands printed out in yellow in the above log.
[10:06:00]: Make sure to inspect the output above, as usually you'll find more error information there
[10:06:00]: 
+------------------------------------+---------------------------------------------------------------------------+
|                                                  Lane Context                                                  |
+------------------------------------+---------------------------------------------------------------------------+
| DEFAULT_PLATFORM                   | ios                                                                       |
| PLATFORM_NAME                      | ios                                                                       |
| LANE_NAME                          | ios beta                                                                  |
| KEYCHAIN_PATH                      | ~/Library/Keychains/***                                                 |
| ORIGINAL_DEFAULT_KEYCHAIN          | "/Users/runner/Library/Keychains/***.keychain-db"                       |
| SIGH_PROFILE_TYPE                  | ad-hoc                                                                    |
| MATCH_PROVISIONING_PROFILE_MAPPING | {"com.reddwarf.musicapp"=>"match AdHoc com.reddwarf.musicapp 1629273389"} |
+------------------------------------+---------------------------------------------------------------------------+
[10:06:00]: Error building the application - see the log above

+------+------------------+-------------+
|           fastlane summary            |
+------+------------------+-------------+
| Step | Action           | Time (in s) |
+------+------------------+-------------+
| 1    | default_platform | 0           |
| 2    | xcode_select     | 0           |
| 3    | create_keychain  | 0           |
| 4    | is_ci            | 0           |
| 5    | match            | 2           |
|    | build_app        | 8           |
+------+------------------+-------------+

[10:06:00]: fastlane finished with errors

[!] Error building the application - see the log above
Error: Process completed with exit code 1.

为什么会这样?我应该怎么做才能解决这个问题?任何帮助表示赞赏。我无法撤销证书,因为证书正在使用中。我也试图找到 iOS 发行版但失败了:

没有找到“iOS 分布”。

如果您想为属于同一开发团队的多个应用程序使用单个开发人员 and/or 分发证书,您可以使用相同的签名身份存储库和分支来存储您的应用程序的签名身份:

App #1 和 #2 的匹配文件示例:

git_url("https://github.com/example/example-repo.git")
git_branch("master")

match 将重复使用证书并为每个应用程序创建单独的配置文件。