使用 xcodebuild 来 archive 并导出 app

之前我曾写过一篇文章macOS app 实现自动化 notarize 脚本,但并没有提到使用代码自动编译并生成 App 的脚本,毕竟这一步有好多工具可以完成,比如说 fastlane。

我由于在 notarize 之前也没想过做自动化,而在写那篇文章的时候 fastlane 还没有支持 notarized 上传,于是我就自己写了,具体的编译命令是这样的:

这样就可以直接把 dsym 和 app 文件生成出来了,方便的很。

……可是好景不长,最近苹果似乎改动了 notarized 服务器行为,之前就一直让人头疼的 sparkle 集成签名问题再度出现,简而言之就是每次使用脚本生成的 app,对 sparkle 的签名总是出现各种问题,而本地检测又是正常的。

作为对比,使用 Xcode 自己的 archive 生成并上传,是一切正常的(我单独给 Sparkle 做了额外的签名代码,是可行的,但用命令编译就不行)。

我猜测可能是直接生成 App 丢失了什么缓存,经过查询,现在分为两步走,先生成正常的 archive ,然后再从 archive 中导出 app。

生成 xcarchive ,这一步没什么好说的,直接就能成功了,接下来的步骤则有点复杂:

选择你刚刚生成的 xcarchive,然后从里边导出 app(并签名),这一步要求了一个奇怪的 -exportOptionsPlist ,且目前在网上也找不到什么完整的模板,总的来说这个配置文件是不用写满全部参数的,把主要参数写了就行,其他参数按默认即可,以前的 Xcode 版本还可以从 archive 功能里导出一份配置文件(这个文件在导出时也存在一份拷贝),现在似乎不能了,总之,我给出一个模板,你可以参考来写,反正如果写错了,它会报错,然后告诉你缺少什么参数,又或者哪个写错了,应该是哪些之一,很好排错:

比如上文中 teamID 和 signingStyle 字段,其实都可以省略,因为 xcodebuild 会自动从你的项目配置中读取。


这下导出的 app 就可以正常 notarized 了。

本文由 落格博客 原创撰写:落格博客 » 使用 xcodebuild 来 archive 并导出 app

转载请保留出处和原文链接:https://www.logcg.com/archives/3385.html

About the Author

R0uter

如非声明,本人所著文章均为原创手打,转载请注明本页面链接和我的名字。

Comments

  1. 你好,請問你有遇過在執行Archive時跳出“Command SetOwnerAndGroup failed with a nonzero exit code”錯誤碼過嗎?
    我不管是用GUI還是參考你的指令都不知道該如何處理掉這個錯誤碼
    爬了蠻多文也去蘋果論壇詢問,目前沒找到有效的處理方式,若你能給些建議或方向會對我來說很有幫助

    謝謝

    1. 很遗憾,这篇文章现在已经过时了,现在我用的脚本是这样的,必须先生成 archive, 然后再导出 app:

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

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

      1. 感謝你的回覆,請問一下你所提供的指令中,若要透過cmd來執行的話,那些中文參數應該怎麼表示會比較恰當?
        謝謝

          1. 我目前透過“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“
            來建立archive,但是在創立過程會出現“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 **”
            請問你有遇到過相關問題嗎?

          2. 仔细读错误提示,它说你没有provisioning profile,这个东西默认是Xcode来保管的,但你改用cli编译的话,Xcode就不管了。你需要自己去苹果开发者网站,登录后找到相关页面手动生成并下载才行呢。

          3. 你好,我思考良久且再次詳細針對錯誤碼尋找可能處理方式但毫無方向著手
            我目前已經在keychain設置好certificate了,profile 也已經下載好放在.xcodeproj同路徑下
            請問關於“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 **”這錯誤碼具體該往哪個方向著手修正?是我該將profile放在某個特定的路徑還是需要透過指令先行將profile設定進某個環境設定裡面?
            亦或是有其他可能修正方向?

            煩請您為我指點個方向或具體做法,非常感謝你

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

            看起来还是找不到文件,既然文件已经有了,那你看看是不是和teamid对应吧?看看appleid有没有弄对,如果你有多个账号的话…………

          5. 看來Xcode 14 之後的driverkit只能使用profile type 是development 而已,不能用developer ID Application
            即使使用您所提供的指令,他在執行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 **

            這邊顯示的“Command SetOwnerAndGroup failed with a nonzero exit code”跟我最一開始在Xcode IDE執行archive所遇到的問題是一樣的

            若我在“xcodebuild -project .. /Activator/Activator.xcodeproj -scheme Activator -archivePath “.. /Embedded Application/Activator.xcarchive” DWARF_DSYM_FOLDER_PATH =”.. /Embedded Application/Activator” – Target General/Platform=macOS Archive“指令前加上sudo則會顯示“error: No profile for team ‘team ID’ matching ‘Profile’ found: Xcode couldn’t find any provisioning profiles matching ‘team ID/profile’.”

            關於operation not permitted問題,我嘗試過直接更改整個專案資料夾的群組及權限,但依然無法處理掉這問題,經過指令產生出來的.app與.dext皆無權限存取內容,導致會跳出operation not permitted
            請問你是否有遇過相關問題呢?

  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.

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注