xcodebuild 存档配置不起作用

Posted

技术标签:

【中文标题】xcodebuild 存档配置不起作用【英文标题】:xcodebuild archive configuration not work 【发布时间】:2012-11-23 11:22:27 【问题描述】:

我想使用 xcodebuild 归档一个具有 3 种不同配置的方案,但配置永远不会随着归档操作而改变。

这是.sh中的内容

xcodebuild -workspace myApp.xcodeproj/project.xcworkspace -sdk iphoneos -scheme myApp -configuration Distribution clean archive

xcodebuild -workspace myApp.xcodeproj/project.xcworkspace -sdk iphoneos -scheme myApp -configuration Inhouse clean archive

xcodebuild -workspace myApp.xcodeproj/project.xcworkspace -sdk iphoneos -scheme myApp -configuration Release clean archive

更新:构建操作工作正常

xcodebuild -workspace myApp.xcodeproj/project.xcworkspace -sdk iphoneos -scheme myApp -configuration Distribution clean build

xcodebuild -workspace myApp.xcodeproj/project.xcworkspace -sdk iphoneos -scheme myApp -configuration Inhouse clean build

xcodebuild -workspace myApp.xcodeproj/project.xcworkspace -sdk iphoneos -scheme myApp -configuration Release clean build

我正在使用 Xcode4.5/ios6.0,它适用于构建操作(每次运行 xcodebuild 都会更改配置),有什么解决方案吗?

【问题讨论】:

【参考方案1】:

存档动作的配置没有效果,可能是xcodebuild的一个bug。

为了改变存档的配置,我写了一个shell脚本,每次运行存档命令之前都会改变scheme的配置。

可能不是最好的解决方案,但解决问题。

代码如下:

#! /bin/sh

# Define Scheme name
PACKAGE_PROJECT_NAME="MyApp"
PACKAGE_SCHEME_NAME="MyApp"

# Get Username
PACKAGE_USER_NAME="$(whoami)"

# Scheme Path
PACKAGE_SCHEME_DIR="$SRCROOT/$PACKAGE_PROJECT_NAME.xcodeproj/xcuserdata/$PACKAGE_USER_NAME.xcuserdatad/xcschemes"
PACKAGE_SCHEME_PATH="$PACKAGE_SCHEME_DIR/$PACKAGE_SCHEME_NAME.xcscheme"

echo "PACKAGE_SCHEME_PATH = $PACKAGE_SCHEME_PATH"

# Set Configuration
# WARNING: BACKUP_CONFIGURATION MUST be same with build configuration of archive action in MyApp scheme
BACKUP_CONFIGURATION="Distribution"

# WARNING: Archive name of archive action in MyApp scheme MUST be set explicitly.
# WARNING: BACKUP_ARCHIVENAME MUST be same with archive name of archive action in MyApp scheme
BACKUP_ARCHIVENAME="MyAppArchive"

echo "BACKUP_CONFIGURATION = $BACKUP_CONFIGURATION"
echo "BACKUP_ARCHIVENAME = $BACKUP_ARCHIVENAME"

# -------------------------------Archive Distribution---------------------------------------
# Set Configuration
OLD_CONFIGURATION="$BACKUP_CONFIGURATION"
NEW_CONFIGURATION="Distribution"
OLD_ARCHIVENAME="$BACKUP_ARCHIVENAME"
NEW_ARCHIVENAME="$PACKAGE_SCHEME_NAME_$NEW_CONFIGURATION"

# Clean
xcodebuild -workspace $PACKAGE_PROJECT_NAME.xcodeproj/project.xcworkspace -sdk iphoneos -scheme $PACKAGE_SCHEME_NAME -configuration $NEW_CONFIGURATION clean

# Change archive configuration
sed -i .bak "/<ArchiveAction/,/<\/ArchiveAction>/s/\"$OLD_CONFIGURATION\"/\"$NEW_CONFIGURATION\"/;s/\"$OLD_ARCHIVENAME\"/\"$NEW_ARCHIVENAME\"/;" $PACKAGE_SCHEME_PATH

# Archive
xcodebuild -workspace $PACKAGE_PROJECT_NAME.xcodeproj/project.xcworkspace -sdk iphoneos -scheme $PACKAGE_SCHEME_NAME archive

# -------------------------------Archive Inhouse------------------------------------------
# Set Configuration
OLD_CONFIGURATION="$NEW_CONFIGURATION"
NEW_CONFIGURATION="Inhouse"
OLD_ARCHIVENAME="$NEW_ARCHIVENAME"
NEW_ARCHIVENAME="$PACKAGE_SCHEME_NAME_$NEW_CONFIGURATION"

# Clean
xcodebuild -workspace $PACKAGE_PROJECT_NAME.xcodeproj/project.xcworkspace -sdk iphoneos -scheme $PACKAGE_SCHEME_NAME -configuration $NEW_CONFIGURATION clean

# Change archive configuration
sed -i .bak "/<ArchiveAction/,/<\/ArchiveAction>/s/\"$OLD_CONFIGURATION\"/\"$NEW_CONFIGURATION\"/;s/\"$OLD_ARCHIVENAME\"/\"$NEW_ARCHIVENAME\"/;" $PACKAGE_SCHEME_PATH

# Archive
xcodebuild -workspace $PACKAGE_PROJECT_NAME.xcodeproj/project.xcworkspace -sdk iphoneos -scheme $PACKAGE_SCHEME_NAME archive

# -------------------------------Archive Adhoc-------------------------------------------
# Set Configuration
OLD_CONFIGURATION="$NEW_CONFIGURATION"
NEW_CONFIGURATION="Release"
OLD_ARCHIVENAME="$NEW_ARCHIVENAME"
NEW_ARCHIVENAME="$PACKAGE_SCHEME_NAME_$NEW_CONFIGURATION"

# Clean
xcodebuild -workspace $PACKAGE_PROJECT_NAME.xcodeproj/project.xcworkspace -sdk iphoneos -scheme $PACKAGE_SCHEME_NAME -configuration $NEW_CONFIGURATION clean

# Change archive configuration
sed -i .bak "/<ArchiveAction/,/<\/ArchiveAction>/s/\"$OLD_CONFIGURATION\"/\"$NEW_CONFIGURATION\"/;s/\"$OLD_ARCHIVENAME\"/\"$NEW_ARCHIVENAME\"/;" $PACKAGE_SCHEME_PATH

# Archive
xcodebuild -workspace $PACKAGE_PROJECT_NAME.xcodeproj/project.xcworkspace -sdk iphoneos -scheme $PACKAGE_SCHEME_NAME archive

# ------------------------------Restore Configuration-------------------------------------
sed -i .bak "/<ArchiveAction/,/<\/ArchiveAction>/s/\"$NEW_CONFIGURATION\"/\"$BACKUP_CONFIGURATION\"/;s/\"$NEW_ARCHIVENAME\"/\"$BACKUP_ARCHIVENAME\"/;" $PACKAGE_SCHEME_PATH

【讨论】:

【参考方案2】:

使用--scheme 选项时,配置会被方案本身的设置覆盖。您将需要创建 3 个不同的方案并配置每个方案以使用适合存档操作的配置:

或者你根本不用担心方案,直接在命令行使用--target--configuration开关。

【讨论】:

构建操作正常(参见我的更新),使用-target 存档操作将无法运行,得到unsupported build action archive 错误。

以上是关于xcodebuild 存档配置不起作用的主要内容,如果未能解决你的问题,请参考以下文章

iOS存档不起作用

Wordpress:带有过滤器的存档页面不起作用(ACF)

存档页面日期的 WP_Query 不起作用

WordPress 自定义帖子类型存档-<帖子类型>.php 不起作用

由于文件间依赖关系,在 Xcode 中创建存档不起作用

WP archive.php 不起作用