每次打包都用图形界面,一方面容易出错,另一方面操作太繁琐,对于一些没有用过xcode的测试人员,打包更是让人头疼,利用shell脚本自动化打包就能解决这些问题,提高打包效率。下面是我在网上查阅相关资料最后形成的shell脚本,可以参考。
#工程绝对路径
project_path=$(pwd)
#build文件夹路径
build_path=${project_path}/build
#工程配置文件路径
project_name=$(ls | grep xcodeproj | awk -F.xcodeproj '{print $1}')
project_infoplist_path=${project_path}/${project_name}/${project_name}-Info.plist
$(/usr/libexec/PlistBuddy -c "Set:CFBundleIdentifier com.xxx.xxxx" ${project_infoplist_path})
$(/usr/libexec/PlistBuddy -c "Set:CFBundleVersion 2.0" ${project_infoplist_path})
<p class="p1">$(/usr/libexec/PlistBuddy -c <span class="s1">"Set:CFBundleShortVersionString 2.0"</span> ${project_infoplist_path})</p>
cd $project_path
echo clean start ...
#删除bulid目录
if [ -d ${build_path} ];then
rm -rf ${build_path}
echo clean build_path success.
fi
#清理工程
xcodebuild clean || exit
#编译工程
#XCODEUUID=`defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilityUUID`
#for f in ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins/*;
#do defaults write "$f/Contents/Info" DVTPlugInCompatibilityUUIDs -array-add $XCODEUUID;
#done
echo $project_path
targetName=$project_name
xcodebuild -target "$targetName" -xcconfig xxx.xcconfig build
if [ -d ./ipa-build ];then
rm -rf ipa-build
fi
#打包
cd $build_path
mkdir -p ipa-build/Payload
cp -r ./Release-iphoneos/*.app ./ipa-build/Payload/
cd ipa-build
zip -r ${project_name}.ipa *
echo ${build_path}/ipa-build/${project_name}.ipa
#找到桌面路径
cd $project_path
#拷贝文件
cp -r ${build_path}/ipa-build/${project_name}.ipa $(pwd)
#清空bulid目录
cd ${build_path}/ipa-build
rm -rf Payload
if [ -d ${build_path} ];then
rm -rf ${build_path}
fi
上面的脚本需要强调下面几点:
1.其中的PlistBuddy工具,需要设置PATH环境变量export PATH=/usr/libexec:$PATH,注意这样设置后只能保证在当前不关闭的命令窗口中有效,在新打开命令行窗口得重新设置。通过PlistBuddy可以更改xxx-info.plist中的内容,如版本号,identifier等。
2.运行上面的脚本可能还会遇到下面这样的错误提示
PluginLoading: Required plug-in compatibility UUID C4A681B0-4A26-480E-93EC-1218098B9AA0 for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/VVDocumenter-Xcode.xcplugin' not present in DVTPlugInCompatibilityUUIDs
解决这个可以用shell命令行
#XCODEUUID=`defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilityUUID`
#for f in ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins/*;
#do defaults write "$f/Contents/Info" DVTPlugInCompatibilityUUIDs -array-add $XCODEUUID;
#done
或者切换到~/Library/Application Support/Developer/Shared/Xcode/Plug-ins目录下,修改其中的info.plist文件将提示中的UUID值添加到DVTPlugInCompatibilityUUIDs中。3.其中的xxx.xcconfig配置文件,这个文件中的内容等价于工程的build-setting设置,具体怎么填写可以参见工程的xxx..pbxproj的文件内容,或者到工程的build-setting中copy,然后再paste到xcconfig文件中。
一般常见的配置有
PRODUCT_NAME =
INFOPLIST_FILE =
PROVISIONING_PROFILE =
PROVISIONING_PROFILE[sdk=iphoneos*] =
CODE_SIGN_IDENTITY =
CODE_SIGN_IDENTITY[sdk=iphoneos*] =
本文参考的文章见:
http://www.cnblogs.com/tangbinblog/p/3783410.html
http://blog.sina.com.cn/s/blog_7011f21c0101bkgr.html
http://blog.csdn.net/linfei2707/article/details/7100514
http://blog.csdn.net/yu0089/article/details/8182128