I am having an ARCHIVE FAILED issue to build flutter project for IOS in my command line with the command

[email protected] myapp-client % /usr/bin/xcodebuild -sdk iphoneos -configuration Release -workspace /Users/admin/Desktop/admin/myapp-client/ios/Runner.xcworkspace -scheme alpha archive -verbose FLUTTER_ROOT=/Users/admin/Desktop/admin/flutter

However, when I click the Achive button in Xcode, it can achive successfully. I got the above command from my Azure DevOps pipeline to build Xcode. I got the same error in Azure DevOps with error code 65 (please see the error log from Azure DevOps at the end of the question).

Both from the Azure DevOps and local command line, I could not tell an obvious error. Can anyone please help? This issue has blocked me to a few weeks but could not get any clue.

Here is a part of build log. Please let me know if you need more. Thank you

Strip /Users/admin/Library/Developer/Xcode/DerivedData/Runner-azykwrtawkhtxmcscwjshiptxdjw/Build/Intermediates.noindex/ArchiveIntermediates/alpha/InstallationBuildProductsLocation/Applications/Runner.app/Runner (in target 'Runner' from project 'Runner')
    cd /Users/admin/Desktop/admin/myapps-client/ios
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip /Users/admin/Library/Developer/Xcode/DerivedData/Runner-azykwrtawkhtxmcscwjshiptxdjw/Build/Intermediates.noindex/ArchiveIntermediates/alpha/InstallationBuildProductsLocation/Applications/Runner.app/Runner

SetOwnerAndGroup admin:staff /Users/admin/Library/Developer/Xcode/DerivedData/Runner-azykwrtawkhtxmcscwjshiptxdjw/Build/Intermediates.noindex/ArchiveIntermediates/alpha/InstallationBuildProductsLocation/Applications/Runner.app (in target 'Runner' from project 'Runner')
    cd /Users/admin/Desktop/admin/myapps-client/ios
    /usr/sbin/chown -RH admin:staff /Users/admin/Library/Developer/Xcode/DerivedData/Runner-azykwrtawkhtxmcscwjshiptxdjw/Build/Intermediates.noindex/ArchiveIntermediates/alpha/InstallationBuildProductsLocation/Applications/Runner.app

SetMode u+w,go-w,a+rX /Users/admin/Library/Developer/Xcode/DerivedData/Runner-azykwrtawkhtxmcscwjshiptxdjw/Build/Intermediates.noindex/ArchiveIntermediates/alpha/InstallationBuildProductsLocation/Applications/Runner.app (in target 'Runner' from project 'Runner')
    cd /Users/admin/Desktop/admin/myapps-client/ios
    /bin/chmod -RH u+w,go-w,a+rX /Users/admin/Library/Developer/Xcode/DerivedData/Runner-azykwrtawkhtxmcscwjshiptxdjw/Build/Intermediates.noindex/ArchiveIntermediates/alpha/InstallationBuildProductsLocation/Applications/Runner.app

CodeSign /Users/admin/Library/Developer/Xcode/DerivedData/Runner-azykwrtawkhtxmcscwjshiptxdjw/Build/Intermediates.noindex/ArchiveIntermediates/alpha/InstallationBuildProductsLocation/Applications/Runner.app (in target 'Runner' from project 'Runner')
    cd /Users/admin/Desktop/admin/myapps-client/ios
    export CODESIGN_ALLOCATE\=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate

    Signing Identity:     "Apple Distribution: Cert (XXXXXX)"
    Provisioning Profile: "My_apps_IOS_Distribution"
                          (Some guid)

    /usr/bin/codesign --force --sign SOME IDENTITY --entitlements /Users/admin/Library/Developer/Xcode/DerivedData/Runner-azykwrtawkhtxmcscwjshiptxdjw/Build/Intermediates.noindex/ArchiveIntermediates/alpha/IntermediateBuildFilesPath/Runner.build/Release-iphoneos/Runner.build/Runner.app.xcent --generate-entitlement-der /Users/admin/Library/Developer/Xcode/DerivedData/Runner-azykwrtawkhtxmcscwjshiptxdjw/Build/Intermediates.noindex/ArchiveIntermediates/alpha/InstallationBuildProductsLocation/Applications/Runner.app

ValidateEmbeddedBinary /Users/admin/Library/Developer/Xcode/DerivedData/Runner-azykwrtawkhtxmcscwjshiptxdjw/Build/Intermediates.noindex/ArchiveIntermediates/alpha/InstallationBuildProductsLocation/Applications/Runner.app/PlugIns/Share\ Extension.appex (in target 'Runner' from project 'Runner')
    cd /Users/admin/Desktop/admin/myapps-client/ios
    /Applications/Xcode.app/Contents/Developer/usr/bin/embeddedBinaryValidationUtility /Users/admin/Library/Developer/Xcode/DerivedData/Runner-azykwrtawkhtxmcscwjshiptxdjw/Build/Intermediates.noindex/ArchiveIntermediates/alpha/InstallationBuildProductsLocation/Applications/Runner.app/PlugIns/Share\ Extension.appex -signing-cert SOME IDENTITY -info-plist-path /Users/admin/Library/Developer/Xcode/DerivedData/Runner-azykwrtawkhtxmcscwjshiptxdjw/Build/Intermediates.noindex/ArchiveIntermediates/alpha/InstallationBuildProductsLocation/Applications/Runner.app/Info.plist
warning: The CFBundleVersion of an app extension ('1') must match that of its containing parent app ('3261').

RegisterExecutionPolicyException /Users/admin/Library/Developer/Xcode/DerivedData/Runner-azykwrtawkhtxmcscwjshiptxdjw/Build/Intermediates.noindex/ArchiveIntermediates/alpha/InstallationBuildProductsLocation/Applications/Runner.app (in target 'Runner' from project 'Runner')
    cd /Users/admin/Desktop/admin/myapps-client/ios
    builtin-RegisterExecutionPolicyException /Users/admin/Library/Developer/Xcode/DerivedData/Runner-azykwrtawkhtxmcscwjshiptxdjw/Build/Intermediates.noindex/ArchiveIntermediates/alpha/InstallationBuildProductsLocation/Applications/Runner.app

Validate /Users/admin/Library/Developer/Xcode/DerivedData/Runner-azykwrtawkhtxmcscwjshiptxdjw/Build/Intermediates.noindex/ArchiveIntermediates/alpha/InstallationBuildProductsLocation/Applications/Runner.app (in target 'Runner' from project 'Runner')
    cd /Users/admin/Desktop/admin/myapps-client/ios
    builtin-validationUtility /Users/admin/Library/Developer/Xcode/DerivedData/Runner-azykwrtawkhtxmcscwjshiptxdjw/Build/Intermediates.noindex/ArchiveIntermediates/alpha/InstallationBuildProductsLocation/Applications/Runner.app

Touch /Users/admin/Library/Developer/Xcode/DerivedData/Runner-azykwrtawkhtxmcscwjshiptxdjw/Build/Intermediates.noindex/ArchiveIntermediates/alpha/InstallationBuildProductsLocation/Applications/Runner.app (in target 'Runner' from project 'Runner')
    cd /Users/admin/Desktop/admin/myapps-client/ios
    /usr/bin/touch -c /Users/admin/Library/Developer/Xcode/DerivedData/Runner-azykwrtawkhtxmcscwjshiptxdjw/Build/Intermediates.noindex/ArchiveIntermediates/alpha/InstallationBuildProductsLocation/Applications/Runner.app

** ARCHIVE FAILED **

The following build commands failed:
    Run custom shell script 'Run Script'
(1 failure)

In Azure DevOps, I tried to rerun the previously passed build (about a week ago). For the first try, I got the follow error

ld: could not reparse object file in bitcode bundle: 'Invalid bitcode version (Producer: '1316.0.21.2.5_0' Reader: '1300.0.29.30_0')', using libLTO version 'LLVM version 13.0.0, (clang-1300.0.29.30)' for architecture arm64

❌  clang: error: linker command failed with exit code 1 (use -v to see invocation)

** ARCHIVE FAILED **

Then I set Enable Bitcode of the Target to No. After that, these errors were fixed and got a different error. Here is a part of the log from Azure DevOps.

Compiling AppDelegate.swift
▸ Copying /Users/runner/Library/Developer/Xcode/DerivedData/Runner-gsjhxdjmxuzkkbgjdidjocbaqrkc/Build/Intermediates.noindex/ArchiveIntermediates/alpha/IntermediateBuildFilesPath/Runner.build/Release-iphoneos/Runner.build/Objects-normal/arm64/Runner-Swift.h
▸ Copying /Users/runner/Library/Developer/Xcode/DerivedData/Runner-gsjhxdjmxuzkkbgjdidjocbaqrkc/Build/Intermediates.noindex/ArchiveIntermediates/alpha/IntermediateBuildFilesPath/Runner.build/Release-iphoneos/Runner.build/Objects-normal/arm64/Runner.swiftdoc
▸ Copying /Users/runner/Library/Developer/Xcode/DerivedData/Runner-gsjhxdjmxuzkkbgjdidjocbaqrkc/Build/Intermediates.noindex/ArchiveIntermediates/alpha/IntermediateBuildFilesPath/Runner.build/Release-iphoneos/Runner.build/Objects-normal/arm64/Runner.swiftdoc
▸ Copying /Users/runner/Library/Developer/Xcode/DerivedData/Runner-gsjhxdjmxuzkkbgjdidjocbaqrkc/Build/Intermediates.noindex/ArchiveIntermediates/alpha/IntermediateBuildFilesPath/Runner.build/Release-iphoneos/Runner.build/Objects-normal/arm64/Runner.swiftmodule
▸ Copying /Users/runner/Library/Developer/Xcode/DerivedData/Runner-gsjhxdjmxuzkkbgjdidjocbaqrkc/Build/Intermediates.noindex/ArchiveIntermediates/alpha/IntermediateBuildFilesPath/Runner.build/Release-iphoneos/Runner.build/Objects-normal/arm64/Runner.swiftmodule
▸ Compiling Runner_vers.c
▸ Compiling GeneratedPluginRegistrant.m
▸ Linking Runner
⚠️  ld: method '-mdm_reversed' in category from /Users/runner/work/1/s/ios/Pods/GoogleMaps/Base/Frameworks/GoogleMapsBase.framework/GoogleMapsBase conflicts with same method from another category
⚠️  ld: method '-mdm_point1' in category from /Users/runner/work/1/s/ios/Pods/GoogleMaps/Base/Frameworks/GoogleMapsBase.framework/GoogleMapsBase conflicts with same method from another category
⚠️  ld: method '-mdm_point2' in category from /Users/runner/work/1/s/ios/Pods/GoogleMaps/Base/Frameworks/GoogleMapsBase.framework/GoogleMapsBase conflicts with same method from another category
▸ Copying GoogleService-Info.plist
▸ Copying AppFrameworkInfo.plist
▸ Compiling Main.storyboard
▸ Compiling LaunchScreen.storyboard
▸ Processing Info.plist
▸ Running script 'Thin Binary'
▸ Generating 'Runner.app.dSYM'
▸ Running script '[CP] Embed Pods Frameworks'
▸ Running script 'Run Script'
▸ Running script '[CP] Copy Pods Resources'
▸ Copying /Users/runner/Library/Developer/Xcode/DerivedData/Runner-gsjhxdjmxuzkkbgjdidjocbaqrkc/Build/Intermediates.noindex/ArchiveIntermediates/alpha/BuildProductsPath/Release-iphoneos/Share\ Extension.appex
    The CFBundleVersion of an app extension ('1') must match that of its containing parent app ('3287').
▸ Touching Runner.app (in target 'Runner' from project 'Runner')
** ARCHIVE FAILED **

The following build commands failed:
    Run custom shell script 'Run Script'
(1 failure)
##[error]Error: /usr/bin/xcodebuild failed with return code: 65