IOS automated Packaging

Source: Internet
Author: User
From: Baidu search R & D department http://stblog.baidu-tech.com /? P = 1295 Summary

As the number of users of Apple handheld devices increases, IOS applications also increase rapidly. As the number of iPhone jailbroken apps increases, packaging for various channels is time-consuming and labor-consuming. This article provides a more intelligent packaging method to reduce the inconvenience it brings.

Tag

IOS packaging, app packaging, iPhone packaging, iPhone automated packaging, IOS channel packaging, and iPhone automatic channel Packaging

 

Automated packaging Background 1. Background

With iOSProgramThe number of released channels has gradually increased. Packaging for each channel has become a technical activity that takes a lot of time and effort, and most of this is done by RD. This takes a lot of time for RD development. Why not write these things into an automated script and then hand it over to QA or PM to complete the packaging process. After some research, we found that there are few such scripts on the Internet, but xcode provides the shell compilation tool xcodebuild and IPA packaging tool xcrun, there is a reason for us to use these two tools to write an automated packaging script to improve our work efficiency and automation.

2. iOS package format and channel package format

1) Reasons for multi-channel production and packaging problems brought about by multiple channels: As handheld devices such as iPhone, iPad, and itouch are selling hot, their applications are also booming, then, after the above devices are jailbroken, they can directly run the IPA package on the jailbroken device instead of downloading it through the appstore, in this way, many channels dedicated to jailbreak mobile phones have been created in China to provide download of IPA packages. As more and more channels are available, packaging for various channels becomes a time-and energy-consuming technical activity. Therefore, we must find an automated way to make packaging more efficient and simple.
2) iOS packages are classified into two formats: appstore binary files and channel packages.
Appstore binary file: A. app binary file can be generated using xcode.
Channel package: the format is. IPA. xcode is used to generate the corresponding channel package before automatic packaging tools are available, and only one channel package can be generated at a time.ChannelsPackageThe channel ID must be manually used before each package, resulting in time consumption, low efficiency, error-prone, and increased risks.

3. Traditional IOS packaging methods

Use xcode to package

1) appstore Binary Package
Open your project, go to "Edit Project Settings", go to the configuration page, select release and click duplicate, copy a new configuration item, and name it distribution. Then go to the build page, and select distribution in the configuration drop-down box on the top. The value corresponding to any iPhone OS device in the code signing identity below selects your Distribution Certificate. Click "build"-> "build" to compile the program.
After the compilation is successful, you can see a. app binary file in the corresponding build directory.
2) channel IPA package
Configure the distribution certificate according to the above steps, and then click "build"-> "Build and archive" to compile the program. Next, open "window" "organizer", select "archived Applications" on the Left bar, select the compiled package from the list on the right, and click "share" on the top right to save the package to the disk.. A. IPA file is generated as a channel package.
Note: The above running device must select "deveice"

4. Traditional Packaging Problems

Time-consuming, manual, low-efficiency, only RD-dependent, error-prone, high release risks, difficulty in QA regression validation, and inintelligence.

Implementation of automated packaging 1. xcodebuild:

Xcodebuild [-Project
] [-Activetarget] [-alltargets] [-target]... [-parallpolicetargets] [-activeconfiguration] [-configuration] [-SDK |] [=]... []...
Xcodebuild [-version [-SDK |]
Xcodebuild [-showsdks]
Xcodebuild [-find] [-SDK |]
Xcodebuild [-list]


You can also enter xcodebuild-help or-H on the terminal to view the specific options.
Show xcodebuildversion: xcodebuild-version
Show the sdks installed in the current system: xcodebuild-showsdks
Display project information: xcodebuild-list in the current directory
Note: When executing the preceding commands, you must locate them in the root directory of the IOS project file. Otherwise, you will be prompted to find irrelevant commands.

2. xcrun introduction:

This tool is mainly used to package an app file into an IPA package. (Mainly used for jailbroken mobile phones ).
The usage is as follows:

1 /Usr/bin/xcrun-SDK iphoneos packageapplication-V [{Target}. app]-O [{target}. IPA] -- sign [{iPhone distribution: XXX}]-embed [{XXX. mobileprovision}]

Where:-V corresponds to the absolute relative path of the app file-O corresponds to the path of the IPA file and the file name-sign
The corresponding company name or personal name-embed in the publishing certificate corresponds to the publishing Certificate file
Note: If the certificate information is configured in the corresponding distribution configuration,-sign and-embed can be ignored.

3. Specific solutions

A) the IPA package and appstore Binary Package of all channels are output from the source program at a time.
To enable automatic script execution to lay all channel packages at a time, you must have a configuration file to store all channel names and channel numbers, the project file should also have a file that stores the current channel number. Every time the program reads the channel number from the file that stores the channel number,The general idea is to use the script to execute the packaging process cyclically. Before each package, use the script to change the file storing the channel number in the project to the latest Channel Number of the current loop, and then package it one by one.
Note: For specific examples, see the appendix.
B) Provide an IPA parent package to generate all other channel packages and appstore packages from the parent package
Some QA questions: how to ensure that all channel packages are the ones they have verifiedCodeWhat about it?
Indeed, the above Code is re-packaged for the program each time. QA usually only has one package for testing and verification. If all the packages are verified, the QA workload is inadvertently increased !! And the risks are uncontrollable. Therefore, based on the above questions, we have come up with a solution:QA only verifies one package (that is, the parent Package). If this package passes verification, we generate packages from other channels through the parent package. In this way, QA does not need to confirm so many channel packages, risks are also effectively controlled.
Maybe you will ask: is it feasible to generate other packages with one package ??
The reason is: because each channel only has a channel number change, and other content does not change, and our channel number is stored in sourceid. in the DAT file, you only need to change the sourceid in the parent package. the content of the DAT file is enough, while the IPA package is compressed in the same zip format,The basic idea is to decompress the parent package through zip, then change the content of sourceid. dat, and then compress it with zip to the corresponding channel package.
IPA package directory:
Note: For specific examples, see the appendix.

Some Problems

When some shell commands do not work on Mac terminals, make sure that your shell scripts are written in the Mac environment instead of copied from other environments such as XP. Because the Mac and XP encoding are different, there may be problems.

Summary:

This method uses the parent package to output packages from other channels: the following benefits are obtained:

I. Reduced the RD workload and QA workload.

Ii. control risks when testing the release program.

Iii. Improved packaging and publishing efficiency. (Dozens of packages only take a few minutes ).

Iv. Improved automation.

V. Generate other packages from the parent package directly in Linux without relying on Mac or xcode.

The appendix uses the xcode environment to generate the shell script code for all packages at a time:

#! /Bin/sh

Xcodebuild clean-configuration distribution // Clean Project

Distdir = "/users/xxxx/Dist"
Releasedir = "build/distribution-iphoneos"
Version = "1_0_0"
Rm-RDF "$ distdir"
Mkdir "$ distdir"
For line in $ (cat data. dat) // read the data. dat file of all channel numbers
Do
Ipafilename = 'echo $ Line | cut-F1-d': ''// channel name
Sourceid = 'echo $ Line | cut-F2-d': ''// channel number
Echo "ipafilename = $ ipaname"
Echo "sourceid = $ sourceid"
Targetname = "youtargename" // project name (project name displayed in the list on the left of xcode)
Echo "sourceid = $ sourceid"
Echo "ipafilename = $ ipafilename"
Echo "$ sourceid"> sourceid. dat
Echo "sourceid. DAT :"
Cat sourceid. dat
Rm-RDF "$ releasedir"

Ipapath = "$ {distdir}/$ {targetname }_$ {version }_from _ $ {sourceid}. IPA"

Echo "*** start to build the app file ***"
Xcodebuild-target "$ targetname"-configuration distribution-SDK iphoneos build
Appfile = "$ {releasedir}/$ {targetname}. app"
If [$ sourceid = "appstore"]
Then
CD $ releasedir
Zip-R "registry.targetname=_registry.ipafilename=_registry.version=.zip" "$ {targetname}. app"
Mv "${targetname1__${ipafilename=.zip" $ distdir 2>/dev/null
CD ../..
Else
Echo "***** getting started with IPA channel package ****"
/Usr/bin/xcrun-SDK iphoneos packageapplication-V "$ appfile"-o "$ ipapath" -- sign "iPhone distribution: xxxxxx"
Fi
Done

Note: The above data. the DAT file is the file that stores the channel number list in the format of 3G: 1001b (channel name: Channel Number) sourceid. dat is the file that stores the channel number in the project file (the content has only one channel number ). Of course, the above script only illustrates how to use xcodebuild and xcrun to package and automatically package the logic. The shell script can be used freely...

Generate shell script instances for other channel packages from the IPA parent package:

#! /Bin/sh
sourceipaname = "parent package name. IPA "
appname =" app file name. APP "// pauload directory item after pressurization. modify the app file name according to your project.
distdir = "/users/LXXX/QA" // package the file storage directory.
Version = "1.0.0"
RM -RDF "$ distdir"
mkdir "$ distdir" Unzip $ sourceipaname // extract the parent package file
for line in $ (cat data. dat) // read and loop the channel number file
DO
ipafilename = 'echo $ Line | cut-F1-d ': ''
sourceid = 'echo $ Line | cut-F2-d ': ''
echo" ipafilename = $ ipaname "
echo" sourceid = $ sourceid "
targetname =" IPA package name "
echo" sourceid = $ sourceid "
echo" ipafilename = $ ipafilename "
Cd payload
Cd $ appname
echo" replace sourceid. dat before: "
CAT sourceid. dat
echo "$ sourceid"> sourceid. dat
echo "replace sourceid. dat after: "
CAT sourceid. dat
If [$ sourceid = "appstroe"]
then
Cd ..
zip-R "using multiple targetname1__using multiple version1__from_using multiple sourceid=.zip" $ appname // appstore binary file

Mv "commandid targetname1__1_version1__from_1_sourceid=.zip" $ distdir
CD ..
Else
CD ../..
Zip-R "$ {targetname }_$ {version }_from _ $ {sourceid}. IPA" payload // pack the package in other channels
Mv "$ {targetname }_$ {version }_from _ $ {sourceid}. IPA" $ distdir
Fi
Done Rm-RDF Payload

Note: The above data. dat is used to store all channel numbers. sourceipaname is the parent package verified by QA, the appname is the file name of the app under the payload directory after the IPA package is pressurized. All the above files must be in the same directory as the script file and executed in the Mac environment.
Related Article

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.