Fastfile增量Bundle版本失败:TestFlight上传报版本重复错误
问题:Fastlane increment_build_number 执行后仍出现TestFlight Build版本重复错误
我使用Fastlane上传MacOS应用到TestFlight,已调用increment_build_number指令递增Bundle版本,但上传时还是收到错误提示:Bundle版本'27'已被使用,必须高于之前上传的版本。
Fastfile 代码
# Fastfile default_platform(:mac) DEVELOPER_APP_ID = ENV["DEVELOPER_APP_ID"] APP_IDENTIFIER = ENV["APP_IDENTIFIER"] PROVISIONING_PROFILE_SPECIFIER = "" TEMP_KEYCHAIN_USER = ENV["TEMP_KEYCHAIN_USER"] TEMP_KEYCHAIN_PASSWORD = ENV["TEMP_KEYCHAIN_PASSWORD"] APPLE_ISSUER_ID = ENV["APPLE_ISSUER_ID"] APPLE_KEY_ID = ENV["APPLE_KEY_ID"] APPLE_KEY_CONTENT = ENV["APPLE_KEY_CONTENT"] GIT_AUTHORIZATION = ENV["GIT_AUTHORIZATION"] TEAM_ID = '752MACT599' ORG_NAME = 'Meter' PROJECT_NAME = 'Meter' SIGH_PROVISIONING_PROFILE_NAME = "com.meter.vpn-client1 AppStore" def delete_temp_keychain(name) delete_keychain( name: name ) if File.exist? File.expand_path("~/Library/Keychains/#{name}-db") end def create_temp_keychain(name, password) create_keychain( name: name, password: password, unlock: false, timeout: 0 ) end def ensure_temp_keychain(name, password) delete_temp_keychain(name) create_temp_keychain(name, password) end update_fastlane desc 'Build, Archive, and Upload to App Store Connect' lane :release do |options| is_nightly = 0 app_identifier = ENV['APP_IDENTIFIER'] scheme = 'Meter' configuration = 'Release' UI.message("Debug: Creating App Store Connect API key...") keychain_name = TEMP_KEYCHAIN_USER keychain_password = TEMP_KEYCHAIN_PASSWORD ensure_temp_keychain(keychain_name, keychain_password) api_key = app_store_connect_api_key( key_id: APPLE_KEY_ID, issuer_id: APPLE_ISSUER_ID, key_content: APPLE_KEY_CONTENT, duration: 1200, in_house: false ) increment_build_number( xcodeproj: "Meter.xcodeproj" ) match( # app_identifier: app_identifier, git_basic_authorization: Base64.strict_encode64(GIT_AUTHORIZATION), additional_cert_types: 'mac_installer_distribution', readonly: false, keychain_name: keychain_name, keychain_password: keychain_password, api_key: api_key, platform: "macos" ) cert( keychain_path: "~/Library/Keychains/#{keychain_name}-db", keychain_password: keychain_password, api_key: api_key, platform: "macos" ) sigh( app_identifier: app_identifier, readonly: false, cert_id: lane_context[SharedValues::CERT_CERTIFICATE_ID], provisioning_name: ENV['SIGH_PROVISIONING_PROFILE_NAME'], ignore_profiles_with_different_name: true, api_key: api_key, platform: "macos" ) update_project_team( path: "Meter.xcodeproj", teamid: TEAM_ID ) gym( project: 'Meter.xcodeproj', scheme: scheme, export_method: 'app-store', configuration: configuration, clean: false, derived_data_path: './build', xcargs: "WARNING_CFLAGS='$(inherited)'", skip_profile_detection: true, ) upload_to_testflight( app_identifier: app_identifier, skip_submission: true, skip_waiting_for_build_processing: true, pkg: './Meter.pkg' ) end
错误日志
[19:42:32]: Successfully exported and signed the pkg file: [19:42:32]: /Users/runner/work/client-app-swift/client-app-swift/Meter.pkg [19:42:32]: ---------------------------------- [19:42:32]: --- Step: upload_to_testflight --- [19:42:32]: ---------------------------------- [19:42:32]: Creating authorization token for App Store Connect API [19:42:33]: Ready to upload new build to TestFlight (App: 6449044498)... [19:42:33]: Going to upload updated app to App Store Connect [19:42:33]: This might take a few minutes. Please don't interrupt the script. [19:42:39]: [altool] 2023-09-27 19:42:39.760 *** Error: The provided entity includes an attribute with a value that has already been used The bundle version must be higher than the previously uploaded version: '27'. (ID: a4eed95a-923c-40d7-a697-0c47012fe8be) (-19232) [19:42:39]: [altool] { [19:42:39]: [altool] NSLocalizedDescription = "The provided entity includes an attribute with a value that has already been used"; [19:42:39]: [altool] NSLocalizedFailureReason = "The bundle version must be higher than the previously uploaded version: ‘27’ (ID: a4eed95a-923c-40d7-a697-0c47012fe8be)"; [19:42:39]: [altool] NSUnderlyingError = "Error Domain=IrisAPI Code=-19241 \"The provided entity includes an attribute with a value that has already been used\" UserInfo={status=409, detail=The bundle version must be higher than the previously uploaded version., source={\n pointer = \"/data/attributes/cfBundleVersion\";\n}, id=a4eed95a-923c-40d7-a697-0c47012fe8be, code=ENTITY_ERROR.ATTRIBUTE.INVALID.DUPLICATE, title=The provided entity includes an attribute with a value that has already been used, meta={\n previousBundleVersion = 27;\n}, NSLocalizedDescription=The provided entity includes an attribute with a value that has already been used, NSLocalizedFailureReason=The bundle version must be higher than the previously uploaded version.}"; [19:42:39]: [altool] "iris-code" = "ENTITY_ERROR.ATTRIBUTE.INVALID.DUPLICATE"; [19:42:39]: [altool] previousBundleVersion = 27; [19:42:39]: [altool] } [19:42:39]: Application Loader output above ^ [19:42:39]: Error uploading '/var/folders/r_/vbvvglrx3lvds6dp_mbyq3_c0000gn/T/881530bf-4d94-4419-84f8-32cb1b667364.pkg'. [19:42:39]: The provided entity includes an attribute with a value that has already been used The bundle version must be higher than the previously uploaded version: '27'. (ID: a4eed95a-923c-40d7-a697-0c47012fe8be) (-19232) [19:42:39]: The call to the altool completed with a non-zero exit status: 1. This indicates a failure. [19:42:39]: Could not download/upload from App Store Connect! +---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Lane Context | +------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | DEFAULT_PLATFORM | mac | | PLATFORM_NAME | | | LANE_NAME | release | | KEYCHAIN_PATH | ~/Library/Keychains/*** | | BUILD_NUMBER | 2 | | SIGH_PROFILE_TYPE | app-store | | MATCH_PROVISIONING_PROFILE_MAPPING | {"***"=>"match AppStore *** macos", "***.extension"=>"match AppStore ***.extension macos"} | | CERT_FILE_PATH | /Users/runner/work/client-app-swift/client-app-swift/7532RULTT7.cer | | CERT_CERTIFICATE_ID | 7532RULTT7 | | SIGH_PROFILE_PATH | /Users/runner/work/client-app-swift/client-app-swift/AppStore_***.provisionprofile | | SIGH_PROFILE_PATHS | ["/Users/runner/work/client-app-swift/client-app-swift/AppStore_***.provisionprofile"] | | SIGH_UDID | 61cc4105-d494-4957-a18a-1a757e194d34 | | SIGH_UUID | 61cc4105-d494-4957-a18a-1a757e194d34 | | SIGH_NAME | match AppStore *** macos | | PKG_OUTPUT_PATH | /Users/runner/work/client-app-swift/client-app-swift/Meter.pkg | | XCODEBUILD_ARCHIVE | /Users/runner/Library/Developer/Xcode/Archives/2023-09-27/Meter 2023-09-27 19.39.33.xcarchive | +------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------+ [19:42:39]: Error uploading pkg file: [Application Loader Error Output]: Error uploading '/var/folders/r_/vbvvglrx3lvds6dp_mbyq3_c0000gn/T/881530bf-4d94-4419-84f8-32cb1b667364.pkg'. [Application Loader Error Output]: The provided entity includes an attribute with a value that has already been used The bundle version must be higher than the previously uploaded version: '27'. (ID: a4eed95a-923c-40d7-a697-0c47012fe8be) (-19232) [Application Loader Error Output]: The call to the altool completed with a non-zero exit status: 1. This indicates a failure. +------------------------------------------------+ | fastlane summary | [!] Error uploading pkg file: [Application Loader Error Output]: Error uploading '/var/folders/r_/vbvvglrx3lvds6dp_mbyq3_c0000gn/T/881530bf-4d94-4419-84f8-32cb1b667364.pkg'. [Application Loader Error Output]: The provided entity includes an attribute with a value that has already been used The bundle version must be higher than the previously uploaded version: '27'. (ID: a4eed95a-923c-40d7-a697-0c47012fe8be) (-19232) [Application Loader Error Output]: The call to the altool completed with a non-zero exit status: 1. This indicates a failure. +------+---------------------------+-------------+ | Step | Action | Time (in s) | +------+---------------------------+-------------+ | 1 | default_platform | 0 | | 2 | update_fastlane | 5 | | 3 | create_keychain | 0 | | 4 | app_store_connect_api_key | 0 | | 5 | increment_build_number | 6 | | 6 | match | 4 | | 7 | cert | 0 | | 8 | sigh | 0 | | 9 | update_project_team | 0 | | 10 | gym | 299 | | 💥 | upload_to_testflight | 6 | +------+---------------------------+-------------+ [19:42:39]: fastlane finished with errors
问题原因
从lane上下文的BUILD_NUMBER = 2可以看出,increment_build_number只是基于本地项目的build号进行了递增,完全没有同步App Store Connect上已存在的最新版本(27),导致生成的安装包版本远低于已上传版本,触发重复错误。
修复方案
1. 基于App Store Connect最新版本递增
修改increment_build_number,通过app_store_build_number获取App Store Connect上的最新版本号,以此为基础进行递增:
increment_build_number( xcodeproj: "Meter.xcodeproj", build_number: app_store_build_number(api_key: api_key) )
注:代码中api_key已经在increment_build_number之前初始化,可直接引用。
2. 同步所有Target的Build号
如果项目包含多个Target(如主App和Extension),需要确保所有Target的Build号同步更新,添加all_targets: true参数:
increment_build_number( xcodeproj: "Meter.xcodeproj", build_number: app_store_build_number(api_key: api_key), all_targets: true )
3. 验证Build号正确性(可选)
在increment_build_number后添加日志,确认Build号是否正确获取并递增:
increment_build_number(...) UI.message("当前使用的Build号: #{lane_context[SharedValues::BUILD_NUMBER]}")
4. CI环境中避免版本覆盖(可选)
如果在CI环境运行,可添加commit_version_bump: true提交版本号变更,防止后续步骤覆盖修改:
increment_build_number( xcodeproj: "Meter.xcodeproj", build_number: app_store_build_number(api_key: api_key), all_targets: true, commit_version_bump: true )
内容的提问来源于stack exchange,提问作者narner
相关产品推荐
相关产品推荐

