xcodebuild和xcrun自动化编译ipa包

You can now run a script which will :

  • Build your application into an .app file
1  xcodebuild -target "${PROJECT_NAME}" -sdk "${TARGET_SDK}" -configuration Release
  • Package it into an .ipa file
1 /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}”

#!/bin/sh

# build.sh
#
# Created by Vincent Daubry on 19/01/10.
# Copyright 2010 OCTO. All rights reserved.

PROJDIR=${WORKSPACE}/___PROJECT NAME___
PROJECT_NAME=___XCODE PROJECT NAME___
TARGET_SDK="iphonesimulator4.0"
PROJECT_BUILDDIR="${PROJDIR}/build/Release-iphoneos"
TARGET_TEST_NAME="UnitTests"
BUILD_HISTORY_DIR="/Users/barbu/Desktop"
DEVELOPPER_NAME="iPhone Developer: M VINCENT DAUBRY (J9TS3TJRYX)"
PROVISONNING_PROFILE = "/Users/barbu/Desktop/desire.mobileprovision"
 
# compile project
echo Building Project
cd "${PROJDIR}"
xcodebuild -target "${PROJECT_NAME}" -sdk "${TARGET_SDK}" -configuration Release

#Check if build succeeded
if [ $? != 0 ]
then
  exit 1
fi

/usr/bin/xcrun -sdk iphoneos PackageApplication -v "${PROJECT_BUILDDIR}/${APPLICATION_NAME}.app" -o "${BUILD_HISTORY_DIR}/${APPLICATION_NAME}.ipa" --sign "${DEVELOPPER_NAME}" --embed "${PROVISONNING_PROFILE}"
转: http://blog.octo.com/en/automating-over-the-air-deployment-for-iphone/

//-----------------------------------------------------------------我是分割线---------------------------------------------------------------------------------------

打包过程

xcodebuild负责将工程源文件编译成xxx.app

xcrun负责给xxx.app(签名并)打包成xxx.ipa


第一步清理:xcodebuild  clean

第二步编译:xcodebuild

第三步打包:xcrun -sdk iphoneos PackageApplication -v path/To/xxx.app -o xxx.ipa


bash shell入门:

http://www.aka.org.cn/Lectures/002/Lecture-2.1.2/index.html

使用getopts命令使用

:表示有参数需要值

[html]  view plain copy
  1. #!/bin/bash  
  2. while getopts h:ms option  
  3. do   
  4.     case "$option" in  
  5.         h)  
  6.             echo "option:h, value $OPTARG"  
  7.             echo "next arg index:$OPTIND";;  
  8.         m)  
  9.             echo "option:m"  
  10.             echo "next arg index:$OPTIND";;  
  11.         s)  
  12.             echo "option:s"  
  13.             echo "next arg index:$OPTIND";;  
  14.         \?)  
  15.             echo "Usage: args [-h n] [-m] [-s]"  
  16.             echo "-h means hours"  
  17.             echo "-m means minutes"  
  18.             echo "-s means seconds"  
  19.             exit 1;;  
  20.     esac  
  21. done  

在使用getopts命令的时候,shell会自动产生两个变量OPTIND和OPTARG。OPTIND初始值为1,其含义是下一个待处理的参数的索引。只要存在,getopts命令返回true,所以一般getopts命令使用while循环;

在while循环中判断 

[html]  view plain copy
  1. if getopts $param_pattern optname ;then  
  2.             echo  "Error argument value for option $tmp_optname"  
  3.             exit 2  
  4.         fi  
可以判断参数值是否是下个参数名称,如果是,就退出

[html]  view plain copy
  1. #判断输入参数是否大与0  
  2. if [ $# -lt 1 ];then  
  3.     echo "Error! Should enter the root directory of xcode project after the ipa-build command."  
  4.     exit 2  
  5. fi  
  6.   
  7. #判断第一个参数是否是目录  
  8. if [ ! -d $1 ];then  
  9.     echo "Error! The first param must be a directory."  
  10.     exit 2  
  11. fi  

xcodebuild使用

[html]  view plain copy
  1. sage: xcodebuild [-project <projectname>] [[-target <targetname>]...|-alltargets] [-configuration <configurationname>] [-arch <architecture>]... [-sdk [<sdkname>|<sdkpath>]] [<buildsetting>=<value>]... [<buildaction>]...  
  2.        xcodebuild -workspace <workspacename> -scheme <schemeName> [-configuration <configurationname>] [-arch <architecture>]... [-sdk [<sdkname>|<sdkpath>]] [<buildsetting>=<value>]... [<buildaction>]...  
  3.        xcodebuild -version [-sdk [<sdkfullpath>|<sdkname>] [<infoitem>] ]  
  4.        xcodebuild -list [[-project <projectname>]|[-workspace <workspacename>]]  
  5.        xcodebuild -showsdks  
  6. Options:  
  7.     -usage                print full usage  
  8.     -verbose              provide additional status output  
  9.     -project NAME         build the project NAME  
  10.     -target NAME          build the target NAME  
  11.     -alltargets           build all targets  
  12.     -workspace NAME       build the workspace NAME  
  13.     -scheme NAME          build the scheme NAME  
  14.     -configuration NAME   use the build configuration NAME for building each target  
  15.     -xcconfig PATH        apply the build settings defined in the file at PATH as overrides  
  16.     -arch ARCH            build each target for the architecture ARCH; this will override architectures defined in the project  
  17.     -sdk SDK              use SDK as the name or path of the base SDK when building the project  
  18.     -parallelizeTargets   build independent targets in parallel  
  19.     -jobs NUMBER          specify the maximum number of concurrent build operations  
  20.     -showsdks             display a compact list of the installed SDKs  
  21.     -list                 lists the targets and configurations in a project, or the schemes in a workspace  
  22.     -find BINARY          display the full path to BINARY in the provided SDK  
  23.     -version              display the version of Xcode; with -sdk will display info about one or all installed SDKs 

转:http://blog.csdn.net/totogo2010/article/details/8883100


参考:http://stackoverflow.com/questions/2664885/xcode-build-and-archive-from-command-line

http://www.neat.io/posts/2010/10/27/automated-ota-ios-app-distribution.html

你可能感兴趣的:(xcodebuild和xcrun自动化编译ipa包)