由题意就可以知道,这个随笔是写一些关于如何使用命令行来打包ipa的,现在我先交待一下技术背景和前提!
来到公司后的第一个项目已经上线了,android的apk打包方式是使用gradle,但是ios的target也有很多,每个target都有n多不同的要求,不同渠道使用的icon也不相同,这些在我们原有的架构上,处理起来都非常花时间,现在的ios渠道已经有7个之多,如果完全由手工去打包,那还是一件体力活,我们要想办法把之变成技术活!
既然是用命令行,那行就少不了xcode的一些编译指令了!所以要先下载 Command Line Tools。
选择download,
因为我的是已经下载过了,所以看不到了~如果有看到Command Line Tools,并且没有下载安装的话,就安装一下!
#/**************************************************************************** # Copyright (c) 2014 Poche Chen # # http://www.cnblogs.com/chiefCTO # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. # Mail: chiefcto@gmail.com # ****************************************************************************/ #!/bin/bash #要编译的target,每个target都是用空隔隔开的,不能是其它符号!!! mTarget=("HeroLegend_PP" "HeroLegend_91" "HeroLegend_GDSDK" "HeroLegend_KY" "HeroLegend_itools" "HeroLegend_SyncPush") #生成的ipa包在路径 mTargetPath="/Users/chenbaicai/Desktop/work" #每个target对应的ipa名称,顺序是和mTarget一一对应的(不包含后缀.ipa) mTargetName=("COT_PP_ALL" "COT_91" "COT_GDSDK" "COT_KY" "COT_itools" "COT_SyncPush") #打包ipa函数 function buildIpa() { echo "正在清理目标$1" #执行clean xcodebuild clean -target $1 echo "复制每个target对应的icon到现有的工程里" #将对应的icon复制到当前的target中,要注意此时的icon的路径! cp -rf ./icon/$1/* ./ #开始对代码进行编译,这个步骤会产生一个.app的程序 #.app可以通过已经安装的tools-command进行打包和签名,将其转成ipa echo "开始build ipa,如果中途出现异常,脚本会终止" xcodebuild -target $1 || exit #使用xcrun对已经生成的app进行打包,并签名 #注:进行签名用的证书必须是存在keychain access里的,建议是直接从keychain access里复制,不宜手打! echo "$1 build successed, making and sign ipa" #如果build成功,那么就开始执行签名,将app转成ipa xcrun -sdk iphoneos PackageApplication -v ./build/Release-iphoneos/*.app -o $mTargetPath/$2.ipa --sign "iPhone Developer: lolex lin (M22Q4Q33ZN)" echo "making and sign ipa successed" } #循环查找所有的target,对每个target进行build包 for((i=0;i<${#mTarget[@]};i++));do #执行build包函数 buildIpa ${mTarget[i]} ${mTargetName[i]} done
以上就是本人用的脚本,脚本里已经写有注解;
注:该脚本必须要放到和.xcodeproj同一级目录下