如何使用Shell指令碼編譯產生Archive檔案並匯出簽名IPA檔案。,

來源:互聯網
上載者:User

如何使用Shell指令碼編譯產生Archive檔案並匯出簽名IPA檔案。,

如何使用Shell指令碼編譯產生Archive檔案並匯出簽名IPA檔案。

1. build 指令碼說明

本Shell指令碼用於build,XCode的workspace原始碼工程,並匯出成可重簽名的IPA檔案,用於分發測試安裝檔案和用於提交appstore審核的檔案。實現輔助產品開發,測試的組態管理工作。

使用本指令碼需要以下環境
- Mac OS 10.9+
- XCode 6.0 or later and command line tools
- 用於WorkSpace工程,例如使用了Cocoapods依賴庫管理的工程
- *配置好開發認證和ad ho 認證(for Debug)和(for Release)
- 原始碼工程中配置好Scheme名字和build
- 對Debug配置和Release配置設定好認證名稱
- 確認在Xcode UI介面中能夠完全build,並通過環境產生Archive和IPA,並正確簽名。
- 在workspace檔案夾下建立build檔案夾

2. 複製指令檔到WorkSpace目錄3. 開啟終端工具,並進入workspace目錄4. 給指令碼執行許可權

chmod 777 ./build_one_target.sh

5. 修改指令碼參數,原始碼裡已經有注釋

需要修改的
workspace name
provisioningProfile
scheme name
build_config

代碼塊

代碼塊文法遵循標準markdown代碼

#!/bin/bash# init build configuration# archive and ipa output pathbuild_path="./build"# workspace namebuild_workspace="workspacename.xcworkspace" # project name and pathproject_path=$(pwd)project_name=$(ls | grep xcodeproj | awk -F.xcodeproj '{print $1}')# provisiong profile nameprovisioningProfile='"XC Ad Hoc: com.xxxxxx.yyyyyy"'# timestamp for ouput file nametimeStamp="$(date +"%Y%m%d_%H%M%S")"echo "$project_path/$build_workspace"if [ ! -d "$project_path/$build_workspace" ]; then    echo  "Error!Current path is not a xcode workspace.Please check, or do not use -w option."    exit 2fi # get the info.plistapp_infoplist_path=${project_path}/${project_name}/${project_name}-AppStore-Info.plistecho ${app_infoplist_path}# get the main versionbundleShortVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleShortVersionString" "${app_infoplist_path}")# get the build versionbundleVersion=$(/usr/libexec/PlistBuddy -c "print CFBundleVersion" "${app_infoplist_path}")# get the svn revisionsvn_revision=$(svn info |grep Revision: |awk   '{print $2}')#`svnversion -c |sed 's/^.*://' |sed 's/[A-Z]*$//'`#svn info |grep Revision: |awk   '{print $2}'#workspace_name='*.xcworkspace'#ls $project_path/$build_workspace &>/dev/null#rtnValue=$?#if [ !$rtnValue = 0 ];then#   #build_workspace=$(echo $(basename $project_path/$workspace_name))#       echo  "Error!Current path is not a xcode workspace.Please check, or do not use -w option."#   exit 2#fi# scheme namebuild_scheme="schemename" # buidl config. the default is Debug|Releasebuild_config="Release"# clean buildclean_cmd='xcodebuild'clean_cmd=${clean_cmd}' clean -workspace '${build_workspace}' -scheme '${build_scheme}' -configuration '${build_config}$clean_cmd >  $build_path/clean_qa.txt || exit# build & archive, generate the archive filearchive_name="targetname_QA_${timeStamp}.xcarchive"archive_path="./build/"$archive_name build_cmd='xcodebuild'build_cmd=${build_cmd}' -workspace '${build_workspace}' -scheme '${build_scheme}' -destination generic/platform=iOS archive -configuration '${build_config}' ONLY_ACTIVE_ARCH=NO -archivePath '${archive_path}echo "** Archiving QA ** to the ${archive_path}"echo ${build_cmd}$build_cmd > ./build/build_archive_qa.log || exitif [ ! -d "${archive_path}" ]; then    echo  "** Error! ARCHIVE QA FAILED ** Please check ./build/build_archive_qa.log."    exit 2else    echo "** ARCHIVE QA SUCCEEDED ** to the ${archive_path}"fi # export to ipa with QA serveripa_name="targetname_QA_adhoc_v${bundleShortVersion}_b${bundleVersion}_rev${svn_revision}_t${timeStamp}.ipa"ipa_path="./build/"$ipa_name ipa_cmd='xcodebuild'ipa_cmd=${ipa_cmd}' -exportArchive -exportFormat ipa -archivePath '${archive_path}' -exportPath '${ipa_path}' -exportProvisioningProfile '${provisioningProfile}echo "** Exporting QA ** to the ${ipa_path}"echo ${ipa_cmd}eval ${ipa_cmd} > ./build/export_ipa_qa.log || exitif [ ! -f "${ipa_path}" ]; then    echo  "** Error! Export IPA QA FAILED ** Please check ./build/export_ipa_qa.log."    exit 2else    echo "** Export IPA QA SUCCEEDED ** to the ${ipa_path}"fi 
6. 執行指令碼

./build_one_target.sh

大一些的工程,大約3-5分鐘完成。
完成之後,在workspace目錄下的build目錄下,會有如下兩個主要檔案。
targetname_QA_20150420_094731.xcarchive
targetname_QA_adhoc_v2.1.1_b44_rev7849_t20150420_094731.ipa

xcarchive檔案很重要,可以用於不同認證簽名的ipa檔案
ipa檔案使用的是adhoc 認證匯出,用於真機測試分發。認證名稱在原始碼中配置。根據不同的產品bundle id,做相應修改,這裡的名稱和認證,僅做示範參考,不具有任何商業意義。

目錄

[TOC]來組建目錄:

  • build 指令碼說明
    • 複製指令檔到WorkSpace目錄
    • 開啟終端工具並進入workspace目錄
    • 給指令碼執行許可權
    • 修改指令碼參數原始碼裡已經有注釋
      • 代碼塊
    • 執行指令碼
      • 目錄

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.