Use xcodebuild to archive and export app

I wrote an article beforemacOS app script to automate notarize,But there is no mention of using code to automatically compile and generate App scripts,After all, there are many tools to complete this step,For example, fastlane。

I didn’t think about automation before notarize,At the time of writing that article, fastlane did not support notarized upload,So I wrote it myself,The specific compilation command is like this:

In this way, the dsym and app files can be directly generated,Very convenient。

...But the good times don't last long,Apple seems to have changed the notarized server behavior recently,The sparkle integration signature problem that has been a headache before reappears,In short, every time you use the app generated by the script,There are always various problems with the signature of sparkle,And local detection is normal。

As a comparison,Generate and upload using Xcode's own archive,Everything is normal (I separately made additional signature code for Sparkle,It works,But compiling with commands will not work)。

I guess it may be that the app is directly generated and lost some cache,After query,Now divided into two steps,Generate a normal archive first ,Then export the app from the archive。

Generate xcarchive ,There is nothing to say in this step,You can succeed directly,The next steps are a bit more complicated:

Select the xcarchive you just generated,Then export the app from inside (and sign),This step requires a strange -exportOptionsPlist ,And currently there is no complete template on the Internet,In general, this configuration file does not need to be filled with all parameters,Just write the main parameters,Other parameters can be as default,The previous Xcode version can also export a configuration file from the archive function (this file also has a copy when exporting),Seems to be unable now,In short,I give a template,You can refer to write,Anyway, if you make a mistake,It will report an error,Then tell you what parameters are missing,Or which one is wrong,Which one should be,Very easy to troubleshoot:

Such as above teamID and signingStyle Field,Actually can be omitted,because xcodebuild Will automatically read from your project configuration。


Now the exported app can be notarized normally。

Original article written by Gerber drop-off:R0uter's Blog » Use xcodebuild to archive and export app

Reproduced Please keep the source and description link:https://www.logcg.com/archives/3385.html

About the Author

R0uter

The non-declaration,I have written articles are original,Reproduced, please indicate the link on this page and my name。

Comments

  1. Hello there,Have you ever encountered the error code "Command SetOwnerAndGroup failed with a nonzero exit code" when executing Archive?
    I don't know how to deal with this error code whether I use the GUI or refer to your instructions
    After climbing a lot of articles, I also went to the Apple forum to ask,No effective solution has been found so far,It would be very helpful for me if you could give me some advice or direction

    Thanks

    1. I'm sorry,This article is now out of date,Now the script I use is like this,archive must be generated first, Then export the app:

      xcodebuild -project ../Activator/Activator.xcodeproj -scheme Activator -archivePath “../EmbededApplications/Activator.xcarchive” DWARF_DSYM_FOLDER_PATH=”../EmbeddedApplications/Activator” -destination generic/platform=macOS archive

      xcodebuild -exportArchive -archivePath “../EmbededApplications/Activator.xcarchive” -exportPath ../EmbededApplications/Applications/ -exportOptionsPlist ./exportOptionsAdHoc.plist -allowProvisioningUpdates

      1. thanks for your reply,In the instructions you provided,If you want to execute it through cmd,How should those Chinese parameters be expressed more appropriately?
        Thanks

          1. I currently use "sudo xcodebuild -project .. /Activator/Activator.xcodeproj -scheme Activator -archivePath “.. /Embedded Application/Activator.xcarchive” DWARF_DSYM_FOLDER_PATH =”.. /Embedded Application/Activator” – Target General/Platform=macOS Archive“
            to build archive,However, during the creation process, a "note: Building targets in dependency order
            /Users/xxx/Desktop/Dext2.2.0commandtest/USBApp.xcodeproj: error: No profile for team ‘team ID’ matching ‘Profile’ found: Xcode couldn’t find any provisioning profiles matching ‘team ID/profile’. Install the profile (by dragging and dropping it onto Xcode’s dock item) or select a different one in the Signing & Capabilities tab of the target editor. (in target ‘AX88179’ from project ‘USBApp’)
            ** ARCHIVE FAILED **”
            Have you encountered related problems?

          2. Read the error message carefully,It says you don't have a provisioning profile,This thing is kept by Xcode by default.,But if you switch to cli to compile,Xcode doesn't care。You need to go to the apple developer site yourself,After logging in, find the relevant page and manually generate and download it.。

          3. Hello there,I thought for a long time and looked for possible solutions to the error code in detail again, but I had no direction to start
            I have already set up the certificate in the keychain,The profile has also been downloaded and placed in the same path as .xcodeproj
            Ask about the "note: Building targets in dependency order
            /Users/xxx/Desktop/Dext2.2.0commandtest/USBApp.xcodeproj: error: No profile for team ‘team ID’ matching ‘Profile’ found: Xcode couldn’t find any provisioning profiles matching ‘team ID/profile’. Install the profile (by dragging and dropping it onto Xcode’s dock item) or select a different one in the Signing & Capabilities tab of the target editor. (in target ‘AX88179’ from project ‘USBApp’)
            ** ARCHIVE FAILED **" This error code, in which direction should I fix it? Should I put the profile in a specific path or do I need to set the profile into a certain environment setting through commands?
            Or are there other possible corrections?

            Please give me some directions or specific methods,thank you very much

          4. error: No profile for team ‘team ID’ matching ‘Profile’ found

            Looks like it still can't find the file,Since the file already has,Then you see if it corresponds to teamid? See if the appleid is correct,If you have multiple accounts...  

          5. It seems that Xcode 14 Afterwards driverkit can only use the profile type is development,Cannot use developer ID Application
            Even with the directive you provided,The following error message will appear when he executes archive:
            SetOwnerAndGroup root:wheel /Users/xxx/Desktop/Dext2.2.0commandtest/Build/Intermediates.noindex/ArchiveIntermediates/AX88179/IntermediateBuildFilesPath/UninstalledProducts/driverkit/bundle ID (in target ‘AX88179’ from project ‘USBApp’)
            cd /Users/xxx/Desktop/Dext2.2.0commandtest
            /usr/sbin/chown -RH root:wheel /Users/xxx/Desktop/Dext2.2.0commandtest/Build/Intermediates.noindex/ArchiveIntermediates/AX88179/IntermediateBuildFilesPath/UninstalledProducts/driverkit/bundle ID
            chown: /Users/xxx/Desktop/Dext2.2.0commandtest/Build/Intermediates.noindex/ArchiveIntermediates/AX88179/IntermediateBuildFilesPath/UninstalledProducts/driverkit/bundle ID/bundle ID: Operation not permitted
            chown: /Users/xxx/Desktop/Dext2.2.0commandtest/Build/Intermediates.noindex/ArchiveIntermediates/AX88179/IntermediateBuildFilesPath/UninstalledProducts/driverkit/bundle ID/embedded.provisionprofile: Operation not permitted
            chown: /Users/xxx/Desktop/Dext2.2.0commandtest/Build/Intermediates.noindex/ArchiveIntermediates/AX88179/IntermediateBuildFilesPath/UninstalledProducts/driverkit/bundle ID/Info.plist: Operation not permitted
            chown: /Users/xxx/Desktop/Dext2.2.0commandtest/Build/Intermediates.noindex/ArchiveIntermediates/AX88179/IntermediateBuildFilesPath/UninstalledProducts/driverkit/bundle ID: Operation not permitted
            Command SetOwnerAndGroup failed with a nonzero exit code

            ** ARCHIVE FAILED **

            The "Command SetOwnerAndGroup failed with a nonzero exit code" displayed here is the same as the problem I encountered when I first executed the archive in the Xcode IDE

            If I am in "xcodebuild -project .. /Activator/Activator.xcodeproj -scheme Activator -archivePath “.. /Embedded Application/Activator.xcarchive” DWARF_DSYM_FOLDER_PATH =”.. /Embedded Application/Activator" – Target General/Platform=macOS Archive" command with sudo before it will display "error: No profile for team ‘team ID’ matching ‘Profile’ found: Xcode couldn’t find any provisioning profiles matching ‘team ID/profile’.”

            About operation not permitted,I have tried directly changing the group and permissions of the entire project folder,But still can't solve this problem,The .app and .dext generated by the command have no permission to access the content,It will lead to jumping out of operation not permitted
            Have you ever encountered related problems?

  2. Hi, first off – many thanks for your blog, it got me started. However the part of xcodebuild -exportArchive doesn’t work for me, especially those -exportOptionsPlist entries that I just CANT get right. xcodebuild keeps emitting nonsense errors and refuses to export my archive – and although the plist entries are kind-of documented in xcodebuild -help | grep exportOptionsPlist — I still can’t get it right. If you managed to make it work, I’d like to contact you for few questions.

Leave a Reply

Your email address will not be published. Required fields are marked *