使用 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,然後從裡邊導出 app(並簽名),這一步要求了一個奇怪的 -exportOptionsPlist ,且目前在網上也找不到什麼完整的模板,總的來說這個配置文件是不用寫滿全部參數的,把主要參數寫了就行,其他參數按默認即可,以前的 Xcode 版本還可以從 archive 功能裡導出一份配置文件(這個文件在導出時也存在一份拷貝),現在似乎不能了,總之,我給出一個模板,你可以參考來寫,反正如果寫錯了,它會報錯,然後告訴你缺少什麼參數,又或者哪個寫錯了,應該是哪些之一,很好排錯:

比如上文中 teamIDsigningStyle 字段,其實都可以省略,因為 xcodebuild聯編 會自動從你的項目配置中讀取。


這下導出的 app 就可以正常 notarized 了。

本文由 落格博客 原創撰寫:落格博客 » 使用 xcodebuild 來 archive 並導出 app

轉載請保留出處和原文鏈接:https://www.logcg.com/archives/3385.html

關於作者

R0uter

如非聲明,本人所著文章均為原創手打,轉載請註明本頁面鏈接和我的名字。

註釋

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

    謝謝

    1. 很遺憾,這篇文章現在已經過時了,現在我用的腳本是這樣的,必須先生成 archive, 然後再導出 app:

      xcodebuild -project ../Activator/Activator.xcodeproj -scheme Activator -archivePath “../嵌入式應用程序/Activator.xcarchive” DWARF_DSYM_FOLDER_PATH =”../嵌入式應用程序/激活器” -目標通用/平台=macOS 存檔

      xcodebuild -exportArchive -archivePath “../嵌入式應用程序/Activator.xcarchive” -導出路徑 ../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. 錯誤: 找不到與“個人資料”匹配的團隊“團隊 ID”的個人資料

            看起來還是找不到文件,既然文件已經有了,那你看看是不是和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. 你好, 首先 – 非常感謝您的博客, 它讓我開始. 但是,xcodebuild -exportArchive的部分不適用於我, 尤其是那些我無法正確理解的-exportOptionsPlist條目. xcodebuild不斷發出廢話錯誤,並拒絕導出我的檔案 – 並且儘管plist條目在xcodebuild -help中有所記錄 | 抓住了exportOptionsPlist — 我還是沒辦法. 如果您設法使它起作用, 我想聯繫您幾個問題.

發表評論

您的電子郵件地址不會被公開. 必填字段標 *