iOS
打包脚本 build.sh
#!/bin/sh
BUILD_PATH=$HOME/Documents/cdts/develop/build //编译路径
ARCHIVE_PATH=$BUILD_PATH/DemoApp //DemoApp替换为App的名字
EXPORT_ARCHIVE_PATH=$BUILD_PATH/DemoApp.xcarchive
EXPOTRT_PATH=$BUILD_PATH/DemoApp.ipa
ROOT_GIT_PATH=$HOME/Documents/cdts/develop/demoapp //Git代码文件根路径
APP_GIT_PATH=$ROOT_GIT_PATH/DemoApp //Git代码文件主工程路径
APPSUBMODULE_GIT_PATH=$ROOT_GIT_PATH/SDK //Git子模块代码文件路径
BRANCH_NAME=develop_1.0.0 //Git分支名
echo "$HOME"
echo "$BUILD_PATH"
echo "$ARCHIVE_PATH"
echo "$EXPORT_ARCHIVE_PATH"
echo "$EXPOTRT_PATH"
echo "$ROOT_GIT_PATH"
echo "$APP_GIT_PATH"
echo "$APPSUBMODULE_GIT_PATH"
echo "$BRANCH_NAME"
echo "### Pull最新代码"
cd $ROOT_GIT_PATH
git pull origin "$BRANCH_NAME" --rebase
#git submodule update
cd $APPSUBMODULE_GIT_PATH
git pull origin master --rebase
#git checkout master
cd $APP_GIT_PATH
echo "### 清除上次编译的文件"
rm -rf $BUILD_PATH/*
echo "### 编译Pods"
xcodebuild -scheme Pods-DemoApp -workspace DemoApp.xcworkspace -configuration Release clean build
echo "### 编译DemoApp"
#Clean 可选
#xcodebuild -scheme DemoApp -workspace DemoApp.xcworkspace -configuration Release clean build
echo "### Archive"
xcodebuild -scheme DemoApp -workspace DemoApp.xcworkspace -configuration Release archive -archivePath "$ARCHIVE_PATH"
#XCODE 6
#xcodebuild -exportArchive -exportFormat ipa -archivePath "build/DemoApp.xcarchive" -exportPath "build/DemoApp.ipa" -exportProvisioningProfile "provision_demoapp"
#xcodebuild -exportArchive -exportFormat ipa -archivePath "build/DemoApp.xcarchive" -exportPath "build/DemoApp.ipa" -exportSigningIdentity "iPhone Distribution: XXX Co., Ltd."
#XCODE 7 需要使用系统的ruby 和 较新版本的gem
echo "### 导出ipa 如果失败,使用rvm use system --default 指定ruby"
xcodebuild -exportArchive -archivePath "$EXPORT_ARCHIVE_PATH" -exportPath "$EXPOTRT_PATH" -exportOptionsPlist "AdHocExportOptions.plist"
echo "### 导出完成"
echo "### 进入到DemoApp目录 Commit Info.plist"
cd $ROOT_GIT_PATH
git commit -a -m "自动打包-提交新Info.plist"
echo "### Pull最新代码"
git pull origin "$BRANCH_NAME" --rebase
#git submodule update
cd $APPSUBMODULE_GIT_PATH
git pull origin master --rebase
echo "### Push最新代码"
cd $ROOT_GIT_PATH
git push origin "$BRANCH_NAME"
cd $APP_GIT_PATH
echo "### 完毕 ###"
版本号自增和打包时间 Run Script
#!/bin/bash
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$INFOPLIST_FILE")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $buildNumber" "$INFOPLIST_FILE"
builddate=`date +"%Y-%m-%d %H:%M:%S"`
if [[ -n "$builddate" ]]; then
#! if BuildDateString doesn't exist, add it
/usr/libexec/PlistBuddy -c "Add :BuildDateString string $builddate" "$INFOPLIST_FILE"
#! and if BuildDateString already existed, update it
/usr/libexec/PlistBuddy -c "Set :BuildDateString $builddate" "$INFOPLIST_FILE"
fi
常见错误
-
xcodebuild -exportArchive 提示ruby错误:
使用rvm use system --default 指定ruby -
链接Embedded Binaries 引起导出ipa失败:
改为Linked Frameworks and Libraries -
切换release 打包找不到库:
build settings -> framework search path 修改为对应的 -
rvm 安装 ruby 之后,必须执行 /bin/bash --login 才能执行 ruby 命令
"echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"' >>~/.bashrc
source ~/.bashrc
ruby -v"
- import CommonCrypto 要终端运行 xcode-select --install
网友评论