IOS command to generate IPA file

Source: Internet
Author: User

#!/bin/bash


#--------------------------------------------

# function: Compile Xcode project and play IPA package

# Instructions for use:

# Compiling project

#ipa-build <project directory> [-C <project Configuration>] [-O <ipa output directory>] [-t &L T;target Name>] [-N]

# Compile workspace

#ipa-build <workspace directory>-w-s <schemeName> [-C <project Configuration>] [-N]

#

# 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-build" folder under the project root path

#-T name of target to compile

#- w compile workspace

#-S NAME corresponds to scheme that needs to be compiled under workspace

#- n Whether the clean works before compiling

# CCF

# E-mail:[email Protected]

# Date Created: 2012/09/24

#--------------------------------------------

# Date Modified: 2013/02/18

# Person Modified: CCF

# What to modify: package to use the Xcrun command, and modify the second parameter

#--------------------------------------------

# Date Modified: 2013/04/25

# Person Modified: CCF

# What to modify: Use getopts to process command parameters and increase the pre-compilation purge option

#--------------------------------------------

# Date Modified: 2013/04/26

# Person Modified: CCF

# What to modify: increase the ability to compile workspace

#--------------------------------------------




If [$#-lt 1];then

echo "error! Should enter the root directory of the Xcode project after the Ipa-build command. "

Exit 2

Fi


if [!-D $];then

echo "error! The first param must be a directory. "

Exit 2

Fi


#工程绝对路径

CD $

project_path=$ (PWD)


#编译的configuration, the default is release

Build_config=release


Param_pattern= ": Nc:o:t:ws:"

optind=2

While getopts $param _pattern optname

Do

Case ' $optname ' in

"N")

Should_clean=y

;;

"C")

Tmp_optind= $OPTIND

Tmp_optname= $optname

tmp_optarg= $OPTARG

optind= $OPTIND-1

If getopts $param _pattern optname; then

echo "Error argument value for option $tmp _optname"

Exit 2

Fi

optind= $tmp _optind


build_config= $tmp _optarg

;;

"O")

Tmp_optind= $OPTIND

Tmp_optname= $optname

tmp_optarg= $OPTARG


optind= $OPTIND-1

If getopts $param _pattern optname; then

echo "Error argument value for option $tmp _optname"

Exit 2

Fi

optind= $tmp _optind


CD $tmp _optarg

output_path=$ (PWD)

if [!-D $output _path];then

echo "error! The value of option o must is an exist directory. "

Exit 2

Fi


;;

"W")

Workspace_name= ' *.xcworkspace '

LS $project _path/$workspace _name &>/dev/null

Rtnvalue=$?

if [$rtnValue = 0];then

Build_workspace=$ (Echo $ (basename $project _path/$workspace _name))

Else

echo "error! Current path was not a Xcode workspace. Please check, or does not use-w option. "

Exit 2

Fi

;;

"S")

Tmp_optind= $OPTIND

Tmp_optname= $optname

tmp_optarg= $OPTARG


optind= $OPTIND-1

If getopts $param _pattern optname; then

echo "Error argument value for option $tmp _optname"

Exit 2

Fi

optind= $tmp _optind


Build_scheme= $tmp _optarg

;;

"T")

Tmp_optind= $OPTIND

Tmp_optname= $optname

tmp_optarg= $OPTARG


optind= $OPTIND-1

If getopts $param _pattern optname; then

echo "Error argument value for option $tmp _optname"

Exit 2

Fi

optind= $tmp _optind


build_target= $tmp _optarg

;;



"?")

echo "error! Unknown option $OPTARG "

Exit 2

;;

":")

echo "error! No argument value for option $OPTARG "

Exit 2

;;

*)

# should not occur

echo "error! Unknown Error while processing options "

Exit 2

;;

Esac

Done



#build文件夹路径

Build_path=${project_path}/build

#生成的app文件目录

Appdirname=release-iphoneos

if [$build _config = Debug];then

Appdirname=debug-iphoneos

Fi

if [$build _config = Distribute];then

Appdirname=distribute-iphoneos

Fi

#编译后文件路径 (only used when compiling workspace)

Compiled_path=${build_path}/${appdirname}


#是否clean

If ["$should _clean" = "Y"];then

Xcodebuild Clean

Fi



#组合编译命令

Build_cmd= ' Xcodebuild '


If ["$build _workspace"! = ""];then

#编译workspace

If ["$build _scheme" = ""];then

echo "error! Must provide a scheme by-s option together when using-w option to compile a workspace. "

Exit 2

Fi

Build_cmd=${build_cmd} '-workspace ' ${build_workspace} '-scheme ' ${build_scheme} '-configuration ' ${build_config} ' Configuration_build_dir= ' ${compiled_path} ' Only_active_arch=no '


Else

#编译project

Build_cmd=${build_cmd} '-configuration ' ${build_config}


If ["$build _target"! = ""];then

Build_cmd=${build_cmd} '-target ' ${build_target}

Fi

Fi



#编译工程

CD $project _path

$build _cmd | | Exit


#进入build路径

CD $build _path


#创建ipa-build Folder

if [-D./ipa-build];then

RM-RF Ipa-build

Fi

mkdir Ipa-build




#app文件名称

appname=$ (basename./${appdirname}/*.app)

#通过app文件名获得工程target名字

target_name=$ (echo $appname | awk-f. ' {print $} ')

#app文件中Info. plist file path

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})


#IPA名称

Ipa_name= "${target_name}_${bundleshortversion}_${build_config}${bundleversion}_$ (date +"%Y%m%d ")"

Echo $ipa _name


#xcrun打包

Xcrun-sdk Iphoneos packageapplication-v./${appdirname}/*.app-o ${build_path}/ipa-build/${ipa_name}.ipa | | Exit


If ["$output _path"! = ""];then

CP ${build_path}/ipa-build/${ipa_name}.ipa $output _path/${ipa_name}.ipa

echo "Copy IPA file successfully to the path $output _path/${ipa_name}.ipa"

Fi


IOS command to generate IPA file

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.