大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
#!/bin/bash
创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站设计、网站制作、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的四川网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!#--------------------------------------------
# 功能:编译xcode项目并打ipa包
# 使用说明:
# 编译project
# ipa-build
# 编译workspace
# ipa-build
#
# 参数说明:-c NAME 工程的configuration,默认为Release。
# -o PATH 生成的ipa文件输出的文件夹(必须为已存在的文件路径)默认为工程根路径下的”build/ipa-build“文件夹中
# -t NAME 需要编译的target的名称
# -w 编译workspace
# -s NAME 对应workspace下需要编译的scheme
# -n 编译前是否先clean工程
# 作者:ccf
# E-mail:ccf.developer@gmail.com
# 创建日期:2012/09/24
#--------------------------------------------
# 修改日期:2013/02/18
# 修改人:ccf
# 修改内容:打包方式改为使用xcrun命令,并修改第二个参数
#--------------------------------------------
# 修改日期:2013/04/25
# 修改人:ccf
# 修改内容:采用getopts来处理命令参数,并增加编译前清除选项
#--------------------------------------------
# 修改日期:2013/04/26
# 修改人:ccf
# 修改内容:增加编译workspace的功能
#--------------------------------------------
if [ $# -lt 1 ];then
echo "Error! Should enter the root directory of xcode project after the ipa-build command."
exit 2
fi
if [ ! -d $1 ];then
echo "Error! The first param must be a directory."
exit 2
fi
#工程绝对路径
cd $1
project_path=$(pwd)
#编译的configuration,默认为Release
build_config=Release
param_pattern=":nc:o:t:ws:"
OPTIND=2
while getopts $param_pattern optname
do
case "$optname" in
"n")
should_clean=y
;;
"c")
tmp_optind=$OPTIND
tmp_optname=$optname
tmp_optarg=$OPTARG
OPTIND=$OPTIND-1
if getopts $param_pattern optname ;then
echo "Error argument value for option $tmp_optname"
exit 2
fi
OPTIND=$tmp_optind
build_config=$tmp_optarg
;;
"o")
tmp_optind=$OPTIND
tmp_optname=$optname
tmp_optarg=$OPTARG
OPTIND=$OPTIND-1
if getopts $param_pattern optname ;then
echo "Error argument value for option $tmp_optname"
exit 2
fi
OPTIND=$tmp_optind
cd $tmp_optarg
output_path=$(pwd)
if [ ! -d $output_path ];then
echo "Error!The value of option o must be an exist directory."
exit 2
fi
;;
"w")
workspace_name='*.xcworkspace'
ls $project_path/$workspace_name &>/dev/null
rtnValue=$?
if [ $rtnValue = 0 ];then
build_workspace=$(echo $(basename $project_path/$workspace_name))
else
echo "Error!Current path is not a xcode workspace.Please check, or do not use -w option."
exit 2
fi
;;
"s")
tmp_optind=$OPTIND
tmp_optname=$optname
tmp_optarg=$OPTARG
OPTIND=$OPTIND-1
if getopts $param_pattern optname ;then
echo "Error argument value for option $tmp_optname"
exit 2
fi
OPTIND=$tmp_optind
build_scheme=$tmp_optarg
;;
"t")
tmp_optind=$OPTIND
tmp_optname=$optname
tmp_optarg=$OPTARG
OPTIND=$OPTIND-1
if getopts $param_pattern optname ;then
echo "Error argument value for option $tmp_optname"
exit 2
fi
OPTIND=$tmp_optind
build_target=$tmp_optarg
;;
"?")
echo "Error! Unknown option $OPTARG"
exit 2
;;
":")
echo "Error! No argument value for option $OPTARG"
exit 2
;;
*)
# Should not occur
echo "Error! Unknown error while processing options"
exit 2
;;
esac
done
#build文件夹路径
build_path=${project_path}/build
#生成的app文件目录
appdirname=Release-iphoneos
if [ $build_config = Debug ];then
appdirname=Debug-iphoneos
fi
if [ $build_config = Distribute ];then
appdirname=Distribute-iphoneos
fi
#编译后文件路径(仅当编译workspace时才会用到)
compiled_path=${build_path}/${appdirname}
#是否clean
if [ "$should_clean" = "y" ];then
xcodebuild clean
fi
#组合编译命令
build_cmd='xcodebuild'
if [ "$build_workspace" != "" ];then
#编译workspace
if [ "$build_scheme" = "" ];then
echo "Error! Must provide a scheme by -s option together when using -w option to compile a workspace."
exit 2
fi
build_cmd=${build_cmd}' -workspace '${build_workspace}' -scheme '${build_scheme}' -configuration '${build_config}' CONFIGURATION_BUILD_DIR='${compiled_path}' ONLY_ACTIVE_ARCH=NO'
else
#编译project
build_cmd=${build_cmd}' -configuration '${build_config}
if [ "$build_target" != "" ];then
build_cmd=${build_cmd}' -target '${build_target}
fi
fi
#编译工程
cd $project_path
$build_cmd || exit
#进入build路径
cd $build_path
#创建ipa-build文件夹
if [ -d ./ipa-build ];then
rm -rf ipa-build
fi
mkdir ipa-build
#app文件名称
appname=$(basename ./${appdirname}/*.app)
#通过app文件名获得工程target名字
target_name=$(echo $appname | awk -F. '{print $1}')
#app文件中Info.plist文件路径
app_infoplist_path=${build_path}/${appdirname}/${appname}/Info.plist
#取版本号
bundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" ${app_infoplist_path})
#取build值
bundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" ${app_infoplist_path})
#IPA名称
ipa_name="${target_name}_${bundleShortVersion}_${build_config}${bundleVersion}_$(date +"%Y%m%d")"
echo $ipa_name
#xcrun打包
xcrun -sdk iphoneos PackageApplication -v ./${appdirname}/*.app -o ${build_path}/ipa-build/${ipa_name}.ipa || exit
if [ "$output_path" != "" ];then
cp ${build_path}/ipa-build/${ipa_name}.ipa $output_path/${ipa_name}.ipa
echo "Copy ipa file successfully to the path $output_path/${ipa_name}.ipa"
fi
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。