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特有的,不适合命令行构建工具。

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

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

其他回答

我已经给出了一个简单的步骤描述,并在使用下面的终端生成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}"

我一直在使用自己的构建脚本为临时分发生成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

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

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

你必须使用的命令是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}"

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

更进一步,用Xcode 7通过命令行上传到iTunesConnect ! (假设您从一个.ipa开始,该ipa已经使用正确的发布概要文件和签名标识进行了签名。)

输入altool,应用程序加载器的CLI界面(文档,第38页)。 隐藏在Xcode的深处。应用程序的结构,是一个方便的功能,让我们直接上传到ItunesConnect。

/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool

只需运行$ altool——upload-app -f file -u username [-p password]即可将你新创建的。ipa文件直接上传到苹果。 密码是可选的,如果您不使用该命令,将提示您输入密码。

如果在验证步骤中应用程序有任何问题,控制台将把它们打印出来。

如果您不想保存路径的位置,则可能必须将路径导出到altool。

export PATH=$PATH:/Applications/Xcode.app/Contents/Applications/Application\ Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/

这就是它!只需登录iTunesConnect.com,选择你的新版本测试testflight。

最后注意:如果你在启动iTunesTransporter时出现异常:Transporter not found at path: /usr/local/itms/bin/iTMSTransporter。你应该重新安装应用程序,你可以按照这个SO答案上的建议,运行一个符号链接到正确的位置:

ln -s /Applications/Xcode.app/Contents/Applications/Application\ Loader.app/Contents/itms /usr/local/itms

打开终端,拖放你的项目文件夹:

cd / \用户/用户名/桌面演示

依次执行以下命令:

将应用程序构建为-“demo”。Xcodeproj”放入存档

Xcodebuild存档项目演示。xcodeproj -scheme demo -archivePath /Users/username/Desktop/demo.xcarchive

如果你的应用程序有Podfile fie as-"demo.xcworkspace"-

xcodebuild -workspace项目名称。xcworkspace -scheme Scheme-Name -sdk iphoneos -configuration Release provision - profile = " Provision-Name " Development_Team= " Team-ID " archive -archivePath /Path/To/Output/AppName。xcarchive存档

IPA导出构建命令

下载ExportOptions。plist文件从这里

xcodebuild -exportArchive -archivePath / ulpa /桌面/演示。xcarchive -exportPath /用户/shilpa/桌面/演示。科学exportionspite /用户/shilpa/导出