Because Xcode manual compilation package is too cumbersome, recently simple implementation of an automatic compilation package shell script here to share with you.
Functions:
- Autocompile
xcarchive
File. - Automatic package export
ipa
File. - automatically
ipa
Upload App Store, dandelion. - Automatic compression and upload
dYSM
(What is dYSM?) the file toBugly. - Three kinds of set
version
andbuild
Version number mode:
1. Retain the current version without modification.
2,build
Number automatically +1.
3. Follow your heartversion
andbuild
Number.
Preparations:
- Downloading shell scripts
First download the file hereshellFile, then put the folder inb.sh
,ADHOCExportOptionsPlist.plist
andAppStoreExportOptionsPlist.plist
Put it in your project root directory (and you.xcodeproj
File level). - Reconfigure the ExportOptionsPlist file that belongs to your project
The easiest way to configure it is to use your own projectExportOptionsPlist
File replacement has just been placed in your project root directoryADHOCExportOptionsPlist.plist
andAppStoreExportOptionsPlist.plist
File. As for generatingExportOptionsPlist
File,You can configure the project certificate, use Xcode with Debug mode and Release mode Archive respectively, and then export itipa
Package,ipa
The ExportOptionsPlist file for the corresponding schema can be found in the same folder as the package. - Configure your own script to replace variable values in the B.sh script, see shell scripts for details.
Execute the script:
- Open a terminal
cd
Go to your project root directory. - use
./b.sh
The command executes the script. - Select the compilation environment
Place enter the number you want to export ? [ 1:app-store 2:ad-hoc]
- Set the version and build versions
Do you want to set a new version for xxxxx ? [ 1:NO 2:Build version + 1 3:YES ]
.
Xcarchive and xxXXXX. ipa are exported to the Build and IPAs folders of ~/Desktop by default.
Script Introduction:
- Get the path of the current shell script folder, that is, the absolute path of the project, the rest of the project starts from this path, easy to obtain the project file.
# CD 'dirname $0' =$(CD 'dirname $0'; pwd)Copy the code
- The basic variable that you need to replace
# scheme_name=" replace your project name with your scheme name"Copy the code
- Gets the date and time used to set the store
xxxxxx.xcarchive
andxxxxxx.ipa
Folder suffix, easy to find the corresponding file later.
# package name suffix (date + time) date = "$(date" + % % % m - Y d_ m - H - % % % S ") "temp_date = ${date}" _"Copy the code
- Get the build environment of your choice,
read
To get the value entered by the terminal, in this case to get your selection1, 2,
Three modes.
echo "Place enter the number you want to export ? Read number while([[$number!= 1]] && [[$number!= 2]]) do echo "Error! Should enter 1 or 2" echo "Place enter the number you want to export ? [ 1:app-store 2:ad-hoc] " read number doneCopy the code
- Based on the compilation environment selected earlier, select
ExportOptionsPlist
File.
if [ $number == 1 ]; then development_mode=Release exportOptionsPlistPath=${project_path}/AppStoreExportOptionsPlist.plist else development_mode=Debug exportOptionsPlistPath=${project_path}/ADHOCExportOptionsPlist.plist fiCopy the code
- through
Info.plist
Get the projectversion
andbuild
Version number, that is, Settingsversion
andbuild
The three modes of the version number.
# set the project version number mainVersion = $(/ usr/libexec/PlistBuddy - c "Print CFBundleShortVersionString" ${project_path}/${project_name}/Info.plist) mainBuild=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" ${project_path}/${project_name}/Info.plist) new_mainVersion=$mainVersion new_mainBuild=$mainBuild echo "${project_name} $mainBuild: $mainBuild" echo "Do you want to set a new version for ${project_name}? [ 1:NO 2:Build version + 1 3:YES ] " # read v_number while([[ $v_number != 1 ]] && [[ $v_number ! = 2 ]] && [[ $v_number != 3 ]]) do echo "Error! Should enter 1, 2, 3" echo "Do you want to set a new version for ${project_name}? [ 1:YES 2:NO 3:Build version + 1 ] " read v_number done # if [ $v_number == 1 ]; Then the echo "/ + + + + + + + the unmodified version number + + + + + + + /" elif [[$v_number = = 2]]. then #build + 1 new_mainBuild=$((${mainBuild} + 1)) else echo "Please enter a new version:?" read version new_mainVersion=$version echo "Please enter a new build:?" Read the build new_mainBuild = $build fi # set the new Version and build plutil - the replace CFBundleShortVersionString - string $new_mainVersion ${project_path}/${project_name}/Info.plist plutil -replace CFBundleVersion -string $new_mainBuild ${project_path}/${project_name}/Info.plistCopy the code
- Build and package projects using XcodeBuild
Echo '/ + + + + + + + is clearing engineering + + + + + + + /' xcodebuild \ the clean - configuration ${development_mode} - the -quiet | | exit echo '/ + + + + + + + clean finish +++++++/' echo 'compiling project :'${development_mode} xcodebuild \ archive -workspace ${project_path}/${project_name}.xcworkspace \ -scheme ${scheme_name} \ -configuration ${development_mode} \ -archivePath ${build_path}/${project_name}.xcarchive - the -quiet | | exit echo '/ + + + + + + + compiler to complete + + + + + + + /' echo '/ + + + + + + + start ipa + + + + + + + packaging/' xcodebuild exportArchive -- archivePath ${build_path}/${project_name}.xcarchive \ -configuration ${development_mode} \ -exportPath ${exportIpaPath} \ - exportOptionsPlist ${exportOptionsPlistPath} \ - quiet | | exit # whether within the IPAs have ipa package if [- e $exportIpaPath / $scheme_name. Ipa ]; Then the echo '/ + + + + + + + ipa export package + + + + + + + /' open $exportIpaPath else echo '/ + + + + + + + ipa package export failure + + + + + + + /' fiCopy the code
- Depending on the compilation environment selected earlier
ipa
Upload the package to the App Store or dandelion (About curl upload dandelion), here to replace the corresponding apple ID and dandelion user key, API key and other parameters. After uploading successfullymv $exportIpaPath $exportIpaPath$append_path
Used heremv
Command to change the folder name to distinguish between upload platforms. Finally storeipa
Package folder name byThe name of the project
,time
,The version number
andThe name of the platform
Composition.
if [ $number == 1 ]; Then # upload App Store echo '/+++++++ upload App Store +++++++/' # verify and upload to App Store altoolPath="/Applications/Xcode.app/Contents/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Versions/A/Support/altool" "$altoolPath" --validate-app -f ${$exportIpaPath}/${scheme_name}. Ipa -u where is your appleID -p where is your password -t ios --output-format XML "$altoolPath" --upload-app -f ${$exportIpaPath}/${scheme_name}. Ipa -u where is your appleID -p where is your password -t ios --output-format XML append_path=" upload to App Store" # change ipA package folder path, add suffix, Mv $exportIpaPath$exportIpaPath$append_path echo '/+++++++ Successfully upload to App Store +++++++/' else # upload dandelion echo '/+++++++ MSG= 'git log-1 --pretty=%B' curl -f "File =@$exportIpaPath/$scheme_name.ipa" \ -f "uKey= url" \ -f "_api_key= url "\ -f "_api key" \ -f "updateDescription=${MSG}" \ -F "password=${PASSWORD}" \ https://qiniu-storage.pgyer.com/apiv1/app/upload Append_path =" upload to dandelion "mv $exportIpaPath$exportIpaPath$append_path echo '/+++++++ successfully upload to dandelion +++++++/' fiCopy the code
- upload
dSYM
andsymbol``.zip
The file toBuglyCurl Curl Curl Curl Curl Curl CurlCurl Uploads the symbol list
#Bugly buglyAppKey=" replace your Bugly app key" buglyAppId=" replace your Bugly app ID "bundleId=" replace your bundle ID" echo '/+++++++ compress dSYM files +++++++/' cd $build_path/$project_name.xcarchive/dSYMs zip -r -o '${project_name}.app.dSYM.zip' "${project_name}. App. DSYM" echo '/ + + + + + + + compressed dSYM file complete + + + + + + + /' echo '/ + + + + + + + upload dSYM file + + + + + + + /' curl - k "https://api.bugly.qq.com/openapi/file/upload/symbol?app_key=$buglyAppKey&app_id=$buglyAppId" --form "api_version=1" --form "app_id=$buglyAppId" --form "app_key=$buglyAppKey" --form "symbolType=2" --form "bundleId=${bundleId}" --form "productVersion=${new_mainVersion}(${new_mainBuild})" --form "channel=appstore" --form "fileName=$project_name.app.dSYM.zip" --form "File =@$build_path/$project_name.xcarchive/dSYMs/$project_name.app.dsym. zip" --verbose echo '\n/+++++++ Uploading the dSYM file is complete + + + + + + + / 'echo' / + + + + + + + compressed symbol file + + + + + + + / 'CD $build_path / $project_name. Xcarchive zip -r -o' symbol. Zip ' "BCSymbolMaps" echo '\ n / + + + + + + + compressed symbol end of file + + + + + + + /' echo '/ + + + + + + + upload symbol file + + + + + + + /' curl - k "https://api.bugly.qq.com/openapi/file/upload/symbol?app_key=$buglyAppKey&app_id=$buglyAppId" --form "api_version=1" --form "app_id=$buglyAppId" --form "app_key=$buglyAppKey" --form "symbolType=2" --form "bundleId=${bundleId}" --form "productVersion=${new_mainVersion}(${new_mainBuild})" --form "fileName=symbol.zip" --form "The file = @ $build_path / $project_name xcarchive/symbol. Zip" -- verbose echo '/ + + + + + + + upload symbol file end + + + + + + + /'Copy the code
The above is the whole iOS auto-build package of shell scripts. You can tailor the scripts to your needs, but the basics of all this are configuring your project’s build environment Certificates and Provisioning Profiles. To get the correct ExportOptionsPlist file.