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中都很好用,不能从命令行复制。


当前回答

我已经给出了一个简单的步骤描述,并在使用下面的终端生成ipa时传递参数:

Go to the folder which contains the MyApp.xcodeproject file in terminal By using the command given below you will get all the Targets of the application /usr/bin/xcodebuild -list After the above command is executed, you will get a list of targets of which you should select a specific target you need to generate .ipa /usr/bin/xcodebuild -target $TARGET -sdk iphoneos -configuration Release The above command builds the project and creates a .app file.The path to locate the .app file is ./build/Release-iphoneos/MyApp.app After Build gets succeeded then execute the following command to generate .ipa of the application using Developer Name and Provisioning Profile using the syntax below: /usr/bin/xcrun -sdk iphoneos PackageApplication -v “${TARGET}.app” -o “${OUTDIR}/${TARGET}.ipa” –sign “${IDENTITY}” –embed “${PROVISONING_PROFILE}”

以上语法中每个参数的解释:

${TARGET}.app                == Target path (ex :/Users/XXXXXX/desktop/Application/build/Release-iphoneos/MyApp.app)
${OUTDIR}                    == Select the output directory(Where you want to save .ipa file)
${IDENTITY}                   == iPhone Developer: XXXXXXX (XXXXXXXXXX)(which can be obtained from Keychain access)
${PROVISONING_PROFILE}   == Path to the provisioning profile(/Users/XXXXXX/Library/MobileDevice/Provisioning Profiles/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.mobileprovision”)

ipa将生成在选定的输出目录"${OUTDIR}"

其他回答

进入你的项目根目录,然后:

xcodebuild -project projectname -activetarget -activeconfiguration archive

对于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大得多。

尝试xctool,它是苹果xcodebuild的替代品,可以更容易地构建和测试iOS和Mac产品。它对持续集成特别有帮助。它有一些额外的功能:

运行与Xcode.app相同的测试。 构建和测试结果的结构化输出。 人性化的,ansi彩色输出。

3号非常有用。我不知道是否有人能读懂xcodebuild的控制台输出,我不能,通常它给了我一行5000+字符。比论文还难读。

xctool: https://github.com/facebook/xctool

如果您使用下一个工具:https://github.com/nomad/shenzhen

那么这个任务就很简单了:

which ipa 1>/dev/null 2>&1 || echo 'no shenzhen. to install use: sudo gem install shenzhen --no-ri --no-rdoc'
ipa build --verbose --scheme "${schemeName}"

Xcode 8:


音标格式:

xcodebuild -exportArchive -exportFormat IPA -archivePath MyMobileApp.xcarchive -exportPath MyMobileApp.ipa -exportProvisioningProfile 'MyMobileApp Distribution Profile'

导出存档MyMobileApp。xcarchive作为一个IPA文件到路径MyMobileApp。Ipa使用 配置文件MyMobileApp分发配置文件。

应用格式:

xcodebuild -exportArchive -exportFormat APP -archivePath MyMacApp.xcarchive -exportPath MyMacApp.pkg -exportSigningIdentity 'Developer ID Application: My Team'

导出存档MyMacApp。xcarchive作为PKG文件保存到MyMacApp路径下。PKG使用的应用程序 阳离子签名身份开发人员ID应用:我的团队。安装程序签名标识 开发人员ID安装程序:My Team隐式用于对导出的包进行签名。

Xcodebuild手册页