Xcode 3.2在Build菜单下提供了一个很棒的新功能,“Build and Archive”,它可以生成一个适合Ad Hoc分发的。ipa文件。你也可以打开管理器,选择“存档应用程序”和“向iTunesConnect提交应用程序”。

有没有办法从命令行(作为构建脚本的一部分)使用“构建和存档”?我假设xcodebuild会以某种方式涉及到,但手册页似乎没有说任何关于这方面的内容。

Michael Grinich要求澄清;以下是你不能用命令行构建的功能,这些功能你只能在“构建和存档”之后用Xcode的管理器实现。

You can click "Share Application..." to share your IPA with beta testers. As Guillaume points out below, due to some Xcode magic, this IPA file does not require a separately distributed .mobileprovision file that beta testers need to install; that's magical. No command-line script can do it. For example, Arrix's script (submitted May 1) does not meet that requirement. More importantly, after you've beta tested a build, you can click "Submit Application to iTunes Connect" to submit that EXACT same build to Apple, the very binary you tested, without rebuilding it. That's impossible from the command line, because signing the app is part of the build process; you can sign bits for Ad Hoc beta testing OR you can sign them for submission to the App Store, but not both. No IPA built on the command-line can be beta tested on phones and then submitted directly to Apple.

我希望有人能来证明我是错的:这两个功能在Xcode GUI中都很好用,不能从命令行复制。


当前回答

实际上,你可以像XCode一样重新编译,这样你就可以测试和发布相同的二进制代码。例如,在我的脚本中(类似于上面的脚本),我以AdHoc构建的形式构建了我的发布版本,然后我将其归档为IPA进行测试,然后使用我的分发证书并创建一个zip文件,这是我发送给苹果的文件。相关的台词是:

codesign -f -vv -s "$DistributionIdentity" "$APPDIR"

其他回答

为了改进Vincent的回答,我写了一个脚本:xcodearchive 它允许您通过命令行存档(生成ipa)您的项目。 可以把它看作xcodebuild命令的姐妹,但用于归档。

代码可在github: http://github.com/gcerquant/xcodearchive

该脚本的一个选项是启用dSYM符号在时间戳存档中的存档。没有理由不再保留这些符号,也没有理由不再标记以后可能收到的崩溃日志。

如何用命令构建iOS项目?

Clean : xcodebuild clean -workspace work-space-name.xcworkspace -scheme scheme-name 

&&

Archive : xcodebuild archive -workspace work-space-name.xcworkspace -scheme "scheme-name" -configuration Release -archivePath IPA-name.xcarchive 

&&

Export : xcodebuild -exportArchive -archivePath IPA-name.xcarchive -exportPath IPA-name.ipa -exportOptionsPlist exportOptions.plist

**What is ExportOptions.plist?**

ExportOptions。plist在Xcode中是必需的。它允许您在创建ipa文件时指定一些选项。当你使用Xcode存档应用程序时,你可以在友好的UI中选择这些选项。

重要:ExportOptions.plist中的发布和开发方法是不同的 应用商店:

exportOptions_release ~ method = app-store

发展

exportOptions_dev ~ method = development

对于Xcode 7,你有一个更简单的解决方案。唯一的额外工作是您必须创建一个用于导出存档的配置plist文件。

(与Xcode 6相比,在xrun的结果中xcodebuild -help, -exportFormat和-exportProvisioningProfile选项不再被提及;前者被删除,后者被-exportOptionsPlist取代。)

步骤1,将目录更改为包含.xcodeproject或.xcworkspace文件的文件夹。

cd MyProjectFolder

第二步,使用Xcode或/usr/libexec/PlistBuddy exportOptions。创建导出选项的Plist文件。顺便说一下,xcrun xcodebuild -help会告诉你必须向plist文件插入哪些键。

第三步,创建。xcarchive文件(实际上是文件夹),如下所示(build/ directory将由Xcode立即自动创建),

xcrun xcodebuild -scheme MyApp -configuration Release archive -archivePath build/MyApp.xcarchive

第四步,像这样导出。ipa文件,这与Xcode6不同

xcrun xcodebuild -exportArchive -exportPath build/ -archivePath build/MyApp.xcarchive/ -exportOptionsPlist exportOptions.plist

现在,您将在build/ directory中获得一个ipa文件。只要把它发送到苹果应用商店。

顺便说一下,Xcode 7创建的ipa文件比Xcode 6大得多。

你是指验证/共享/提交选项吗?我认为这些都是Xcode特有的,不适合命令行构建工具。

如果有点聪明的话,我打赌你可以编写一个脚本来为你做这件事。看起来它们只是存储在~/Library/MobileDevice/Archived Applications/中,有一个uuddi和一个plist。我也无法想象反向工程验证器会有那么难。

我感兴趣的自动化过程是将构建版本发送给beta测试人员。(因为App Store很少提交,所以我不介意手动完成,特别是因为我经常需要添加新的描述文本。)通过使用Xcode的CLI执行伪Build+Archive,我可以从每次代码提交中触发自动构建,创建带有嵌入式配置文件的IPA文件,并将其通过电子邮件发送给测试人员。

更新到Xcode 8后,我发现企业ipa生成由

/usr/bin/xcrun -sdk iphoneos PackageApplication -v "${RELEASE_BUILDDIR}/${APPLICATION_NAME}.app" -o "${BUILD_HISTORY_DIR}/${APPLICATION_NAME}.ipa" --sign "${DEVELOPER_NAME}" --embed "${PROVISONING_PROFILE}" 

由于某些签名问题,命令无法启动。日志 表示“警告:PackageApplication已弃用,请使用 用xcodebuild -exportArchive代替。

所以我切换到xcodebuild -exportArchive,一切恢复正常。