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


当前回答

我发现这里的其他一些答案很难展开。这篇文章为我做到了。有些路径可能需要是绝对的,正如在其他答案中提到的那样。

命令:

xcrun -sdk iphoneos PackageApplication \
    "/path/to/build/MyApp.app" \
    -o "output/path/to/MyApp.ipa" \
    --sign "iPhone Distribution: My Company" \
    --embed "/path/to/something.mobileprovision"

其他回答

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

xcodebuild -project projectname -activetarget -activeconfiguration archive

我一直在使用自己的构建脚本为临时分发生成ipa包。

die() {
    echo "$*" >&2
    exit 1
}

appname='AppName'
config='Ad Hoc Distribution'
sdk='iphoneos3.1.3'
project_dir=$(pwd)

echo using configuration $config

echo updating version number
agvtool bump -all
fullversion="$(agvtool mvers -terse1)($(agvtool vers -terse))"
echo building version $fullversion

xcodebuild -activetarget -configuration "$config" -sdk $sdk build || die "build failed"

echo making ipa...
# packaging
cd build/"$config"-iphoneos || die "no such directory"
rm -rf Payload
rm -f "$appname".*.ipa
mkdir Payload
cp -Rp "$appname.app" Payload/
if [ -f "$project_dir"/iTunesArtwork ] ; then
    cp -f "$project_dir"/iTunesArtwork Payload/iTunesArtwork
fi

ipaname="$appname.$fullversion.$(date -u +%Y%m%d%H%M%S).ipa"
zip -r $ipaname Payload

echo finished making $ipaname

脚本还增加版本号。如果不需要,你可以去掉那部分。希望能有所帮助。

如何用命令构建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

我发现了如何从命令行自动化构建和归档过程,我刚刚写了一篇博客文章来解释如何实现这一点。

你必须使用的命令是xcrun:

/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}"

你可以在文章中找到所有的细节。如果你有任何问题,不要犹豫,尽管问。

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

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

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

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