1

I want to use xcodebuild to archive one scheme with 3 different configurations, but the configuration is never changed with archive action.

Here is the content in .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

update: build action works fine

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

I am using Xcode4.5/iOS6.0, It works fine with build action(configuration changes each xcodebuild run), any solution?

2 Answers 2

4

The configuration for archive action has no effect, maybe it's a bug of xcodebuild.

In order to change the configuration of archive, I write a shell script change the configuration of scheme each time before run archive command.

May not be the best solution, but solve the problem.

Here is the code:

#! /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}
Sign up to request clarification or add additional context in comments.

Comments

0

When using the --scheme option, the configuration is overridden by the settings in the Scheme itself. You will need to create 3 different schemes and configure each to use the appropriate configuration for the Archive action:

enter image description here

Alternatively you can not bother with schemes at all, and use the --target and --configuration switches on the command line directly.

1 Comment

The build action works fine(see my update), use -target the archive action won't run, get unsupported build action archive error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.