码迷,mamicode.com
首页 > 移动开发 > 详细

自己写的一个IOS自动打包脚本工具

时间:2015-01-26 20:50:56      阅读:404      评论:0      收藏:0      [点我收藏+]

标签:

#!/bin/bash

#----------------------------------------------------------------------------------
# 功能:编译xcode项目并打ipa包
# 使用说明:
# 编译project
# ipa-package <project directory> [-c <project configuration>] [-n] [-o <ipa output directory>]
#
# 参数说明: -c NAME 工程的configuration,默认为Release。
# -o PATH 生成的ipa文件输出的文件夹(必须为已存在的文件路径)默认为工程根路径下的”build/ipa_package“文件夹中
# -n 编译前是否先clean工程
#----------------------------------------------------------------------------------

#参数判断:必须有第一个参数(工程目录) 否则出错
if [ $# -lt 1 ];then
echo "Error! Should enter the root directory of xcode project after the ipa_package command."
exit 2
fi
#参数判断:第一个参数必须是一个工程目录 否则报错
if [ ! -d $1 ];then
echo "Error! The first param must be a directory."
exit 2
fi

#获取当前路径
current_path=$(pwd)

#进入当前工程目录
cd $1
project_path=$(pwd)

#默认configuration为Release
build_config=Release


#查看输入参数列表
echo "参数数目:$#"
echo "命令名称:$0"
echo "第一个参数:$1"
echo "第二个参数:$2"
echo "参数列表:$@"
echo "show parm list:$*"
echo "show process id:$$"
echo "show precomm stat: $?"


#对于参数的判断处理
param_pattern=":nc:o:"

OPTIND=2
while getopts $param_pattern optname
do
case "$optname" in
"n")
echo ‘nnnnnnnnnnnnnnn‘
should_clean=y
echo $should_clean
;;

"o")
echo ‘oooooooooooooooo‘
tmp_optarg=$OPTARG
echo $(pwd)
cd ${current_path}/$tmp_optarg
output_path=$(pwd)
cd $project_path
output_path=${current_path}/$tmp_optarg
echo $output_path
if [ ! -d $output_path ];then
echo "Error!The value of option o must be an exist directory."
exit 2
fi
;;
"c")
echo ‘cccccccccccccccc‘
tmp_optarg=$OPTARG
build_config=$tmp_optarg
;;
"?")
echo ‘????????????????‘
echo "Error! Unknown option $OPTARG"
exit 2
;;
":")
echo ‘::::::::::::::::‘
echo "Error! No argument value for option $OPTARG"
exit 2
;;
*)
# Should not occur
echo ‘****************‘
echo "Error! Unknown error while processing options"
exit 2
;;
esac
done


build_path=${project_path}/build

appdirname=Release-iphoneos

#如果需要clean项目 需要先clean工程
if [ "$should_clean" = "y" ];then
xcodebuild clean
fi

#编译该工程
xcodebuild -configuration ${build_config}

cd $build_path

#创建默认文件夹用于存放默认的IPA文件
mkdir ipa_package

#获取当前的工程编译完成的app文件
appname=$(basename ./${appdirname}/*.app)
#获取当前工程的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})
#取displayName
identifier=$(/usr/libexec/PlistBuddy -c "print CFBundleIdentifier" ${app_infoplist_path})
#组合成IPA名称
ipa_name="${identifier}_${bundleShortVersion}_${build_config}_${bundleVersion}_$(date +"%Y%m%d%H%M%S")"

echo $ipa_name

#xcrun打包命令
xcrun -sdk iphoneos PackageApplication -v ./${appdirname}/*.app -o ${build_path}/ipa_package/${ipa_name}.ipa || exit

if [ "$output_path" != "" ];then
cp ${build_path}/ipa_package/${ipa_name}.ipa $output_path/${ipa_name}.ipa
echo "Copy ipa file successfully to the path $output_path/${ipa_name}.ipa"
fi

 

自己写的一个IOS自动打包脚本工具

标签:

原文地址:http://www.cnblogs.com/ayann204/p/4251193.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!