之前我曾写过一篇文章macOS app 实现自动化 notarize 脚本,但并没有提到使用代码自动编译并生成 App 的脚本,毕竟这一步有好多工具可以完成,比如说 fastlane。
我由于在 notarize 之前也没想过做自动化,而在写那篇文章的时候 fastlane 还没有支持 notarized 上传,于是我就自己写了,具体的编译命令是这样的:
1 |
xcodebuild -project xxx.xcodeproj -scheme xxx DSTROOT="./" DWARF_DSYM_FOLDER_PATH="./Applications" archive |
这样就可以直接把 dsym 和 app 文件生成出来了,方便的很。
……可是好景不长,最近苹果似乎改动了 notarized 服务器行为,之前就一直让人头疼的 sparkle 集成签名问题再度出现,简而言之就是每次使用脚本生成的 app,对 sparkle 的签名总是出现各种问题,而本地检测又是正常的。
作为对比,使用 Xcode 自己的 archive 生成并上传,是一切正常的(我单独给 Sparkle 做了额外的签名代码,是可行的,但用命令编译就不行)。
我猜测可能是直接生成 App 丢失了什么缓存,经过查询,现在分为两步走,先生成正常的 archive ,然后再从 archive 中导出 app。
1 |
xcodebuild archive -project xxx.xcodeproj -scheme xxx -configuration release -archivePath ./Applications/xxx.xcarchive |
生成 xcarchive ,这一步没什么好说的,直接就能成功了,接下来的步骤则有点复杂:
1 |
xcodebuild -exportArchive -archivePath ./Applications/xxx.xcarchive -exportPath ./Applications/ -exportOptionsPlist ./exportOptionsAdHoc.plist -allowProvisioningUpdates |
选择你刚刚生成的 xcarchive,然后从里边导出 app(并签名),这一步要求了一个奇怪的 -exportOptionsPlist ,且目前在网上也找不到什么完整的模板,总的来说这个配置文件是不用写满全部参数的,把主要参数写了就行,其他参数按默认即可,以前的 Xcode 版本还可以从 archive 功能里导出一份配置文件(这个文件在导出时也存在一份拷贝),现在似乎不能了,总之,我给出一个模板,你可以参考来写,反正如果写错了,它会报错,然后告诉你缺少什么参数,又或者哪个写错了,应该是哪些之一,很好排错:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>provisioningProfiles</key> <dict> <key>com.logcg.inputmethod.LogInputMac.Settings</key> <string>SettingsLGCloud</string> <key>com.logcg.inputmethod.LogInputMac2</key> <string>LogInputMac2</string> </dict> <key>method</key> <string>developer-id</string> <key>iCloudContainerEnvironment</key> <string>Production</string> <key>signingCertificate</key> <string>Developer ID Application</string> <key>signingStyle</key> <string>manual</string> <key>teamID</key> <string>---</string> </dict> </plist> |
比如上文中 teamID 和 signingStyle 字段,其实都可以省略,因为 xcodebuild 会自动从你的项目配置中读取。
这下导出的 app 就可以正常 notarized 了。
本文由 落格博客 原创撰写:落格博客 » 使用 xcodebuild 来 archive 并导出 app
转载请保留出处和原文链接:https://www.logcg.com/archives/3385.html
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.
Hi Motti, just paste xcodebuild error here reply to me, let’s see what we got. 🙂
动手能力令人佩服
也是没办法的事,毕竟每次发布app要是都手动操作,也很繁琐
还很容易在各个过程当中出现意外错误 XD