iPhone packaging steps

Xcodebuild and xcrun implement automatic packaging of iOS applications

2011-12-03 20:30:07 Source: Baidu Search R&D Department Author:

As the number of users of Apple handheld devices continues to increase, ios applications are also growing rapidly. At the same time, as the iphone is jailbroken, more and more app channels are also increasing. Packaging each channel has become a time-consuming and laborious task. This article provides a A more intelligent packaging method to reduce the various inconveniences it brings.

As the number of users of Apple handheld devices continues to increase, ios applications are also growing rapidly. At the same time, as the iphone is jailbroken, more and more app channels are also increasing. Packaging each channel has become a time-consuming and laborious task. This article provides a A more intelligent packaging method to reduce the various inconveniences it brings.

Introduction to the background of automated packaging

1. Background

With the gradual increase in the distribution channels of ios programs, packaging for each channel has become a particularly time-consuming and labor-intensive technical task, and most of this is generally done by rd. This takes up a lot of development time of rd, 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, I found that there are still very few such scripts on the Internet, but xcode provides the shell compilation tool xcodebuild and the ipa packaging tool xcrun, which is why we use these two tools to write an automated packaging script to improve our work efficiency and automation.

2. ios package format, channel package format

1) Reasons for multi-channels and packaging problems brought about by multi-channels: With the hot sales of handheld devices such as iphone, ipad, and itouch, the applications on them are also booming, and the above devices follow After being jailbroken, you can directly run the ipa program package on the jailbroken device without downloading it through the appstore. In this way, there are many channels in China that provide the download of the ipa program package specially for jailbroken mobile phones. With more and more channels, packaging for each channel during promotion has become a time-consuming and energy-consuming technical task, so we must find an automated way to make packaging efficient and simple.
2) The Ios program package is divided into two formats: appstore binary file and channel package.
Appstore binary file: a binary file in .app format can be generated through the xcode tool.
Channel package: the format is .ipa format. Before there is no automatic packaging tool, xcode is used to generate the corresponding channel package, and only one channel package can be generated at a time. Before each package, the channel ID must be manually brought. The problem is that it is time-consuming, inefficient, error-prone, and risky.

3. Traditional ios packaging method

Packaging with xcode

1) Appstore binary package
Open your project, enter "Edit Project Settings", enter the Configuration page, select Release and click Duplicate below, copy a new configuration item and name it Distribution. Then enter the Build page, select Distribution in the Configuration drop-down box on the top, and select your Distribution certificate for the corresponding value behind Any iPhone OS Device in Code Signing Identity below . Then 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. Then open "Window""Organizer", select "ARCHIVED APPLICATIONS" in the left column, then select the package just compiled in the list on the right, and click the "Share" button on the top right to save it to the disk. A .ipa file will be generated as the channel package.
Note: The above operating devices must select "Deveice"

4. Problems brought by traditional packaging

Time-consuming, labor-intensive, inefficient, can only rely on RD to complete, error-prone, release risk is relatively high, QA regression confirmation is difficult, and it is not intelligent.

Realization of automated packaging

C/C++ Code copy content to clipboard
  1. xcodebuild[-project][-activetarget][-alltargets][-target]...[-parallelizeTargets][-activeconfiguration][-configuration][-sdk |][=]...[]...   
  2. xcodebuild[-version[-sdk |]]   
  3. xcodebuild[-showsdks]   
  4. xcodebuild[-find ][-sdk |]   
  5. xcodebuild[-list]  

 

1. Introduction to xcodebuild:

You can also enter in the terminal: xcodebuild –help or –h to view the specific options
Display xcodebuildversion: xcodebuild –version
displays the SDK installed in the current system: xcodebuild –showsdks
displays the project information in the current directory: xcodebuild –list
Note: Execute the above command The location must be located in the root directory of the ios project file, otherwise it will prompt to find irrelevant commands.

2. Introduction to xcrun:

This tool is mainly used to package the app file into a package in ipa format. (mainly for jailbroken phones).
The specific usage is as follows:

Among them: -v corresponds to the absolute relative path of the app file –o corresponds to the path and file name of the ipa file –sign
corresponds to the corresponding company name or personal name in the release certificate –embed corresponds to the release certificate
file If the relevant certificate information has been configured in the distribution configuration of the --sign and --embed can be ignored

3. Specific plan

a) Print out the ipa package of all channels and the binary package of appstore from the source program at one time.
In order to let the automation script execute once to complete all the channel packages, there must be a configuration file to store all the channel names and channel numbers. In the project file, there should also be 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 in a loop . In the past, the file storing the channel number in the project was modified by script to be the latest channel number of the current cycle, and then packaged one by one.
Note: For specific examples, see appendix

b) Provide a parent package in ipa format to generate all other channel packages and appstore package
qa from the parent package. How to ensure that all channel packages are the codes they have verified?
Indeed, the above code repackages the program every time, but qa often tests and verifies only one package. If you verify all of them, you will inadvertently increase the workload of qa! ! And the risks are uncontrollable. Therefore, based on the above problem, we came up with a solution: qa only verifies one program package (that is, the mother package). If the package passes the verification, we will use the mother package to generate packages from other channels, so that qa does not need to confirm so many The channels are covered, and the risks are effectively controlled.
You may ask: Is it feasible to use one package to generate other packages? ?
The reason is this: because each channel only changes the channel number, but other content does not change, and our channel number is stored in the sourceid.dat file, so we only need to change the sourceid in the parent package The content of the .dat file is enough, and the ipa package is compressed in the same zip format, so the basic idea is to first decompress the parent package through zip, then change the content of sourceid.dat, and finally compress it into the corresponding channel package with zip That's it.
The directory of the Ipa package: Note: See the appendix for specific examples\

some problems

When some shell commands fail to run in the mac terminal, please make sure that your shell script is written in the mac environment and not copied from other environments such as xp. Because the encoding of mac and xp is different, there will be problems.

Summarize:

By printing packages from other channels from the parent package: get the following benefits

i. Reduced the workload of rd and the workload of qa.

ii. Keep the risk of testing the release under control.

iii. Improve the efficiency of packaging and publishing. (Dozens of packages in just a few minutes).

iv. Increased automation.

v. Generate other packages from the parent package directly under Linux without relying on the mac and xcode environment

appendix

Use the xcode environment to generate shell script code for all packages at once:

C/C++ Code copy content to clipboard
  1. #!/bin/sh  
  2.   
  3. xcodebuild clean -configuration Distribution      //clean项目   
  4.   
  5. distDir="/Users/xxxx/dist"  
  6. releaseDir="build/Distribution-iphoneos"  
  7. version="1_0_0"  
  8. rm -rdf "$distDir"  
  9. mkdir "$distDir"  
  10. for  line in $(cat data.dat)         //read all channel number data.dat files  
  11. do  
  12. ipafilename=`echo $line|cut -f1 -d ':'//channel name  
  13. sourceid=`echo $line|cut -f2 -d ':' `     //channel number  
  14. echo "ipafilename=$ipaname"  
  15. echo "sourceid=$sourceid"  
  16. targetName= "youtargename"    //Project name (the project name displayed in the list on the left of xcode)  
  17. echo "sourceid=$sourceid"  
  18. echo "ipafilename=$ipafilename"  
  19. echo "$sourceid" > sourceid.dat   
  20. echo "sourceid.dat: "  
  21. cat sourceid.dat   
  22. rm -rdf "$releaseDir"  
  23.   
  24. ipapath="${distDir}/${targetName}_${version}_from_${sourceid}.ipa"  
  25.   
  26. echo  "***start building app files***"  
  27. xcodebuild -target "$targetName" -configuration Distribution  -sdk iphoneos build   
  28. appfile="${releaseDir}/${targetName}.app"  
  29. if [ $sourceid == "appstore" ]   
  30. then   
  31. cd $releaseDir   
  32. zip -r "${targetName}_${ipafilename}_${version}.zip" "${targetName}.app"  
  33. mv "${targetName}_${ipafilename}.zip" $distDir 2> /dev/null   
  34. cd ../..   
  35. else  
  36. echo  "***Start playing ipa channel package****"  
  37. /usr/bin/xcrun -sdk iphoneos PackageApplication -v "$appfile" -o "$ipapath" --sign "iPhone Distribution:xxxxxx"  
  38. fi   
  39. done  

 

Note: The above data.dat file is the file storing the list of channel numbers. The format is: 3g:1001b (channel name: channel number) sourceid.dat is the file storing the channel number in the project file (the content is only one channel number). Of course, the above script just explains how to use xcodebuild and xcrun to package and automatically package a logic. Students who are good at shell script can play freely. . .

A shell script example for generating other channel packages from the parent package in ipa format:

copy content to clipboard
  1. #!/bin/sh  
  2. sourceipaname= "parent package name.ipa"  
  3. appname=”app file name.app”   //After pressurization, the Pauload directory item.app file name needs to be modified according to your own project  
  4. distDir= "/Users/lxxx/Qa"    //File storage directory after packaging  
  5. version="1.0.0"  
  6. rm -rdf "$distDir "  
  7. mkdir  "$distDir"  unzip $sourceipaname      //Unzip the main package file  
  8. for  line in $(cat data.dat)    //read the channel number file and loop  
  9. do  
  10. ipafilename=`echo $line|cut -f1 -d':'`   
  11. sourceid=`echo $line|cut -f2 -d':'`   
  12. echo "ipafilename=$ipaname"  
  13. echo "sourceid=$sourceid"  
  14. targetName= "ipa package name"  
  15. echo "sourceid=$sourceid"  
  16. echo "ipafilename=$ipafilename"  
  17. cd Payload   
  18. cd $appname   
  19. echo "replace sourceid.dat before: "  
  20. cat sourceid.dat   
  21. echo "$sourceid" > sourceid.dat   
  22. echo "replace sourceid.dat after: "  
  23. cat sourceid.dat   
  24. if [ $sourceid == "appstroe" ]   
  25. then   
  26. cd ..   
  27. zip -r  "${targetName}_${version}_from_${sourceid}.zip"  $appname  //appstore binary  
  28.   
  29. mv "${targetName}_${version}_from_${sourceid}.zip" $distDir   
  30. cd ..   
  31. else  
  32. cd ../..   
  33. zip -r  "${targetName}_${version}_from_${sourceid}.ipa"  Payload    // package into other channels  
  34. mv "${targetName}_${version}_from_${sourceid}.ipa" $distDir   
  35. fi   
  36. done rm -rdf Payload  

 

Note: the above data.dat is also used to store all channel numbers, sourceipaname is the parent package that has passed qa verification, appname is the name of the app file in the Payload directory after the ipa package is pressurized, and all the above files must be kept in the same directory as the script file Under and in the mac environment.

Original: http://stblog.baidu-tech.com/?p=1295


Repost analysis:

In xcode4.3 , traditional ios packaging:

Packaging with xcode

Channel ipa package
Configure the Distribution certificate, then click "Build" –> "Archive" to compile the program and automatically pop up the Archive configuration page. You can also open "Organizer", select "Archives" in the left column, then select the package just compiled in the list on the right, click the "Distribute" button on the right top of the right, and then select the Save for Enterprise or Ad-hoc Deployment option, click After Next, select the Code sign certificate, click Next, and save it to disk. A .ipa file will be generated as the channel package. If you want to generate a plist file for network use, just check Save for Enterprise Distribution.

Note: The above operating devices must select "Deveice"


Guess you like

Origin blog.csdn.net/rsp19801226/article/details/7381997