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 需要使用系統(tǒng)的ruby 和 較新版本的gem
echo "### 導(dǎo)出ipa 如果失敗,使用rvm use system --default 指定ruby"
xcodebuild -exportArchive -archivePath "$EXPORT_ARCHIVE_PATH" -exportPath "$EXPOTRT_PATH" -exportOptionsPlist "AdHocExportOptions.plist"
echo "### 導(dǎo)出完成"
echo "### 進(jìn)入到DemoApp目錄 Commit Info.plist"
cd $ROOT_GIT_PATH
git commit -a -m "自動(dòng)打包-提交新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 "### 完畢 ###"
版本號(hào)自增和打包時(shí)間 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
常見(jiàn)錯(cuò)誤
xcodebuild -exportArchive 提示ruby錯(cuò)誤:
使用rvm use system --default 指定ruby鏈接Embedded Binaries 引起導(dǎo)出ipa失敗:
改為L(zhǎng)inked Frameworks and Libraries切換release 打包找不到庫(kù):
build settings -> framework search path 修改為對(duì)應(yīng)的rvm 安裝 ruby 之后缓窜,必須執(zhí)行 /bin/bash --login 才能執(zhí)行 ruby 命令
"echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"' >>~/.bashrc
source ~/.bashrc
ruby -v"
- import CommonCrypto 要終端運(yùn)行 xcode-select --install