Self-written iOS automatic packaging script tool

Source: Internet
Author: User

#!/bin/bash

#----------------------------------------------------------------------------------
# function: Compile Xcode project and play IPA package
# Instructions for use:
#编译project
#ipa-package <project directory> [-C <project Configuration>] [-N] [-o <ipa output directory>]
#
# parameter Description: The configuration of the-C name project, the default is release.
#-o path generates an IPA file in the output folder (must be an existing file path) by default to the "Build/ipa_package" folder under the project root path
#-n Clean Works before compiling
#----------------------------------------------------------------------------------

#参数判断: Must have first parameter (project catalog) otherwise an error
If [$#-lt 1];then
echo "error! Should enter the root directory of the Xcode project after the Ipa_package command. "
Exit 2
Fi
#参数判断: The first parameter must be a project catalog or an error
if [!-D $];then
echo "error! The first param must be a directory. "
Exit 2
Fi

#获取当前路径
current_path=$ (PWD)

#进入当前工程目录
CD $
project_path=$ (PWD)

#默认configuration为Release
Build_config=release


#查看输入参数列表
echo "Number of parameters: $#"
echo "Command name: $"
echo "First parameter: $ $"
echo "second parameter: $"
echo "parameter list: [email protected]"
echo "Show Parm list:$*"
echo "Show Process id:$$"
echo "Show Precomm stat: $?"


#对于参数的判断处理
Param_pattern= ": Nc:o:"

optind=2
While getopts $param _pattern optname
Do
Case ' $optname ' in
"N")
Echo ' nnnnnnnnnnnnnnn '
Should_clean=y
Echo $should _clean
;;

"O")
Echo ' Oooooooooooooooo '
tmp_optarg= $OPTARG
echo $ (PWD)
CD ${current_path}/$tmp _optarg
output_path=$ (PWD)
CD $project _path
output_path=${current_path}/$tmp _optarg
Echo $output _path
if [!-D $output _path];then
echo "error! The value of option o must is an exist directory. "
Exit 2
Fi
;;
"C")
Echo ' CCCCCCCCCCCCCCCC '
tmp_optarg= $OPTARG
build_config= $tmp _optarg
;;
"?")
Echo '???????????????? '
echo "error! Unknown option $OPTARG "
Exit 2
;;
":")
Echo ':::::::::::
echo "error! No argument value for option $OPTARG "
Exit 2
;;
*)
# should not occur
Echo ' **************** '
echo "error! Unknown Error while processing options "
Exit 2
;;
Esac
Done


Build_path=${project_path}/build

Appdirname=release-iphoneos

#如果需要clean项目 need to clean the project first
If ["$should _clean" = "Y"];then
Xcodebuild Clean
Fi

#编译该工程
Xcodebuild-configuration ${build_config}

CD $build _path

#创建默认文件夹用于存放默认的IPA文件
mkdir Ipa_package

#获取当前的工程编译完成的app文件
appname=$ (basename./${appdirname}/*.app)
#获取当前工程的plist文件
App_infoplist_path=${build_path}/${appdirname}/${appname}/info.plist
#取版本号
bundleshortversion=$ (/usr/libexec/plistbuddy-c "Print Cfbundleshortversionstring" ${app_infoplist_path})
#取build值
bundleversion=$ (/usr/libexec/plistbuddy-c "Print Cfbundleversion" ${app_infoplist_path})
#取displayName
identifier=$ (/usr/libexec/plistbuddy-c "Print Cfbundleidentifier" ${app_infoplist_path})
#组合成IPA名称
Ipa_name= "${identifier}_${bundleshortversion}_${build_config}_${bundleversion}_$ (date +"%Y%m%d%H%M%S ")"

Echo $ipa _name

#xcrun打包命令
Xcrun-sdk Iphoneos packageapplication-v./${appdirname}/*.app-o ${build_path}/ipa_package/${ipa_name}.ipa | | Exit

If ["$output _path"! = ""];then
CP ${build_path}/ipa_package/${ipa_name}.ipa $output _path/${ipa_name}.ipa
echo "Copy IPA file successfully to the path $output _path/${ipa_name}.ipa"
Fi

Self-written iOS automatic packaging script tool

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.