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 9和Swift更新我的答案
存档
xcodebuild -workspace <ProjectName>/<ProjectName>.xcworkspace \
-scheme <schemeName> clean archive -configuration release \
-sdk iphoneos -archivePath <ProjectName>.xcarchive
IPA输出(请注意输出选项plist)
xcodebuild -exportArchive -archivePath <ProjectName>.xcarchive \
-exportOptionsPlist <ProjectName>/exportOptions.plist \
-exportPath <ProjectName>.ipa
对于那些不了解exportOptions.plist的人,
https://blog.bitrise.io/post/new-export-options-plist-in-xcode-9
那些在CI/CD工具(如teamcity/jenkins)中使用此工具构建项目的人,请确保您在构建代理中安装了正确的Xcode用于存档和导出。
您可以使用以下两个选项中的任何一个。
使用xcodebuild的完整路径,
/Applications/Xcode 9.3.1.app/Contents/Developer/usr/bin/xcodebuild
使用xcode-select,
xcode-select -switch /Applications/Xcode 9.3.1.app
以下是我以前的回答
下面是创建存档和IPA示例的命令行脚本。
我有一个iPhone xcode项目,位于Desktop/MyiOSApp文件夹。
依次执行以下命令:
cd /Users/username/Desktop/MyiOSApp/
xcodebuild -scheme MyiOSApp archive \
-archivePath /Users/username/Desktop/MyiOSApp.xcarchive
xcodebuild -exportArchive -exportFormat ipa \
-archivePath "/Users/username/Desktop/MyiOSApp.xcarchive" \
-exportPath "/Users/username/Desktop/MyiOSApp.ipa" \
-exportProvisioningProfile "MyCompany Distribution Profile"
这是用Xcode 5测试的,对我来说工作很好。
xcodebuild工具可以使用-exportArchive标记构建和导出存档产品(从Xcode 5开始)。导出步骤以前只能通过Xcode Organizer UI实现。
首先存档你的应用:
xcodebuild -scheme <scheme name> archive
给定$ARCHIVE_PATH (.xcarchive文件的路径),使用以下方法之一从存档中导出应用程序:
iOS .ipa文件:
xcodebuild -exportArchive -exportFormat ipa -archivePath "$ARCHIVE_PATH" -exportPath "myApp.ipa" -exportProvisioningProfile "My App Provisioning profile"
Mac .app文件:
xcodebuild -exportArchive -exportFormat app -archivePath "$ARCHIVE_PATH" -exportPath "myApp.app" -exportSigningIdentity "Developer ID Application: My Software Company"
在这两个命令中-exportProvisioningProfile和-exportSigningIdentity参数都是可选的。查阅xcodebuild以获得语义的详细信息。在这些例子中,iOS版本的配置文件指定了AdHoc分发配置文件,Mac应用程序的签名标识指定了作为第三方应用程序导出的开发者ID(即不通过Mac应用程序商店分发)。
我们使用XCode 4.2.1开发了一款iPad应用,并希望将其整合到我们的持续集成(Jenkins)中,以便OTA发行。下面是我想到的解决方案:
# Unlock keychain
security unlock-keychain -p jenkins /Users/jenkins/Library/Keychains/login.keychain
# Build and sign app
xcodebuild -configuration Distribution clean build
# Set variables
APP_PATH="$PWD/build/Distribution-iphoneos/iPadApp.app"
VERSION=`defaults read $APP_PATH/Info CFBundleShortVersionString`
REVISION=`defaults read $APP_PATH/Info CFBundleVersion`
DATE=`date +"%Y%m%d-%H%M%S"`
ITUNES_LINK="<a href=\"itms-services:\/\/?action=download-manifest\&url=https:\/\/xxx.xxx.xxx\/iPadApp-$VERSION.$REVISION-$DATE.plist\">Download iPad2-App v$VERSION.$REVISION-$DATE<\/a>"
# Package and verify app
xcrun -sdk iphoneos PackageApplication -v build/Distribution-iphoneos/iPadApp.app -o $PWD/iPadApp-$VERSION.$REVISION-$DATE.ipa
# Create plist
cat iPadApp.plist.template | sed -e "s/\${VERSION}/$VERSION/" -e "s/\${DATE}/$DATE/" -e "s/\${REVISION}/$REVISION/" > iPadApp-$VERSION.$REVISION-$DATE.plist
# Update index.html
curl https://xxx.xxx.xxx/index.html -o index.html.$DATE
cat index.html.$DATE | sed -n '1h;1!H;${;g;s/\(<h3>Aktuelle Version<\/h3>\)\(.*\)\(<h3>Ältere Versionen<\/h3>.<ul>.<li>\)/\1\
${ITUNES_LINK}\
\3\2<\/li>\
<li>/g;p;}' | sed -e "s/\${ITUNES_LINK}/$ITUNES_LINK/" > index.html
然后Jenkins将ipa、plist和html文件上传到我们的web服务器。
这是plist模板:
<?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>items</key>
<array>
<dict>
<key>assets</key>
<array>
<dict>
<key>kind</key>
<string>software-package</string>
<key>url</key>
<string>https://xxx.xxx.xxx/iPadApp-${VERSION}.${REVISION}-${DATE}.ipa</string>
</dict>
<dict>
<key>kind</key>
<string>full-size-image</string>
<key>needs-shine</key>
<true/>
<key>url</key>
<string>https://xxx.xxx.xxx/iPadApp.png</string>
</dict>
<dict>
<key>kind</key>
<string>display-image</string>
<key>needs-shine</key>
<true/>
<key>url</key>
<string>https://xxx.xxx.xxx/iPadApp_sm.png</string>
</dict>
</array>
<key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>xxx.xxx.xxx.iPadApp</string>
<key>bundle-version</key>
<string>${VERSION}</string>
<key>kind</key>
<string>software</string>
<key>subtitle</key>
<string>iPad2-App</string>
<key>title</key>
<string>iPadApp</string>
</dict>
</dict>
</array>
</dict>
</plist>
要设置此设置,必须将分发证书和配置配置文件导入到指定用户的keychain中。
打开终端,拖放你的项目文件夹:
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/导出