Xcodebuild and Xcrun enable automated packaging of iOS apps

Source: Internet
Author: User

With the growing number of Apple handheld devices, iOS apps are growing fast, and as the iphone gets more and more apps are being jailbroken, it's a time-consuming task to package each channel, and this article provides a smarter way to pack and reduce the inconvenience.

Introduction to automated packaging background 1, background

As iOS programs release more and more channels, packaging for each channel becomes a particularly time-consuming and physical technique, most of which is done by Rd. This takes a lot of RD development time, 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, this kind of script is still very small, but Xcode provides shell compiler tool xcodebuild and IPA Packaging tool Xcrun, which makes it reasonable for us to use these two tools to write an automated packaging script to improve our productivity and automation level.

2. ios package format, channel package format

1) The causes of multi-channel and multi-channel packaging problems: With the iphone, ipad, itouch and other handheld devices sold hot, and their applications are also hot up, and the resulting is that the above devices are jailbroken after the jailbreak device can run directly on the IPA package Instead of downloading through AppStore, the country has produced a number of channels dedicated to jailbreak mobile phones to provide an IPA package download. As more and more channels are being packaged for each channel, it becomes a time-consuming and energy-intensive technology, so we must look for an automated way to make packaging efficient and simple.
2) iOS package is divided into two formats AppStore binary file and channel package
AppStore binaries: The Xcode tool allows you to generate a. App-formatted binary file.
Channel package: In the format. IPA format, before the automated packaging tools are used to generate the appropriate channel package, and only one channel package can be generated at a time, each time the packaging before the manual of the channel ID, the problem is time-consuming, inefficient, error-prone, increased risk.

3. Traditional iOS Packaging method

Package with Xcode

1) AppStore binary Package
Open your project, go to "Edit project Settings", go to the Configuration page, select release click on the duplicate below, copy a new configuration item, named distribution. Then go to the Build page, the top Configuration drop-down box selected distribution, the following code Signing identity inside any iPhone OS The corresponding value after the device selects your distribution certificate. Then click "Build" –> "build" to compile the program.
Once the compilation is successful, you will be able to see a. App binary file in the appropriate build directory.

2) Channel IPA package
Follow the steps above to configure the distribution certificate, then click "Build" –> "Build and Archive" to compile the program. Then open "window"? " Organizer "Choose archived applications in the left column and then select the package you just compiled in the right-hand list and click on the" Share "button at the top right-hand side to save to disk. A. IPA file is generated as a channel bundle.
Note: The above operating device must select "Deveice"

4, the traditional packaging brings problems

Time consuming, energy consuming, inefficient, can only rely on rd to complete, error prone, release risk is relatively high, QA regression confirmation is more difficult, not intelligent.

Automated packaging specific implementationsC + + Codecopy 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, Xcodebuild Introduction:

You can also view specific options in Terminal input: Xcodebuild–help or –h
Show Xcodebuildversion:xcodebuild–version
Displays the Sdk:xcodebuild–showsdks of the current system installation
Displays the current directory under Project Information:xcodebuild–list
Note that you must locate the location in the root directory of the iOS project file if you execute the above command, or you will be prompted for an unrelated command.

2, Xcrun Introduction:

This tool is primarily used to package app files into an IPA-formatted package. (mainly used for jailbroken mobile phones).
The specific usage is as follows:

Where:-V corresponds to the absolute relative path of the app file –o the path to the IPA file and the filename –sign
corresponding to the corresponding company name or personal name in the certificate of publication –embed corresponding to the publishing certificate file
Note If the relevant certificate information is already configured in the corresponding distribution configuration, –sign and –embed can be ignored

3, the specific plan

A) from the source program all channels of the IPA package with AppStore binary package
In order for the automation script to be executed once all the channel package is good, so there must be a configuration file to store all channel name and channel number, and the project file should also have a corresponding to store the current channel number of the file, each time the program from the file to store channel number to read the channel number can be, The general idea is to use a script loop to carry out the packaging process, and each time before packaging through a script to modify the project to hold the channel number file is the current cycle of the latest channel number, let the later packaging.
Note: See Appendix for specific examples
b) provide an IPA-format master package to generate all other channel packages and AppStore packets from the parent package
QA questions, how do you make sure that all the channel packs are the code they've verified?
Indeed, each time the above code is to re-package the program, QA can often test the verification of only one package, if all to verify inadvertently added to the workload of the QA ha!! And the risks are not manageable. So based on the above question we came up with a way:QA verifies only one package (that is, the parent package) if the package by verifying that we go through the parent package to generate other channels of the package, so that QA does not have to confirm so many channel package, the risk has been effectively controlled.
Perhaps you would ask: Is it possible to generate other packages with one package?
The reason is this: Because each channel is only the channel number changes, and the other content does not change, And our channel number is stored in the Sourceid.dat this file, so as long as the content of the Sourceid.dat file in the parent package can be changed, and the IPA package is also compressed with the ZIP format, so the basic idea is to unpack the parent package by Zip first, Then change the content of the sourceid.dat and then compress it into the corresponding channel package by zip.
Directory of IPA packages:
Note: See Appendix for specific examples

Some questions

When some shell commands do not pass through the Mac's terminal, make sure your shell scripts are written in a Mac environment instead of being copied from other environments such as XP. Because Mac and XP code is not the same, so there will be problems.

Summarize:

By making packages from the parent package to other channels this approach: get the following benefits

I. Reduce the workload of Rd, together with the workload of QA.

II. The risk of testing the release process is under control.

III. Improved packaging release efficiency. (Dozens of packs in just a few minutes).

Iv. improved automation.

V. Do not rely on Mac and Xcode environment directly under Linux to complete the generation of other packages from the parent package

The appendix uses the Xcode environment to generate shell script code for all packages at once:C + + Codecopy content to clipboard
  1. #!/bin/sh   
  2. xcodebuild clean-configuration Distribution //clean Project   
  3. distdir= "/users/xxxx/dist"   
  4. releasedir= "Build/distribution-iphoneos"   
  5. version= "1_0_0"   
  6. RM-RDF "$distDir"   
  7. mkdir "$distDir"   
  8. for Line in $ (cat data.dat) //Read all channel numbers Data.dat file   
  9. Do   
  10. ipafilename= ' echo $line |cut-f1-d ': ' `  //Channel name   
  11. sourceid= ' echo $line |cut-f2-d ': ' `     //channel number   
  12. Echo "Ipafilename= $ipaname"   
  13. Echo "Sourceid= $sourceid"   
  14. targetname= "Youtargename" //project name (the project name shown in the list on the left of Xcode)
  15. Echo "Sourceid= $sourceid"   
  16. Echo "Ipafilename= $ipafilename"   
  17. Echo "$sourceid" > Sourceid.dat
  18. Echo "Sourceid.dat:"   
  19. Cat Sourceid.dat
  20. RM-RDF "$releaseDir"   
  21. ipapath= "${distdir}/${targetname}_${version}_from_${sourceid}.ipa"   
  22. Echo "* * * Start build App file * * *"   
  23. Xcodebuild-target "$targetName" -configuration distribution-sdk Iphoneos Build
  24. appfile= "${releasedir}/${targetname}.app"   
  25. if [$sourceid = = "AppStore" ]
  26. Then
  27. CD $releaseDir
  28. Zip-r "${targetname}_${ipafilename}_${version}.zip" "${targetname}.app"
  29. MV "${targetname}_${ipafilename}.zip" $distDir 2>/dev/null
  30. Cd.. /..
  31. Else   
  32. Echo "* * * start playing IPA Channel package * * * *"   
  33. /usr/bin/xcrun-sdk Iphoneos packageapplication-v "$appfile" - o "$ipapath" --sign "IPhone distribution:xxxxxx"   
  34. Fi
  35. Done

Note: The above Data.dat file is the file that holds the channel number list in the format: 3g:1001b (channel name: Channel number) Sourceid.dat the file for the channel number in the project file (the content has only one channel number). Of course, the script above just shows how to use Xcodebuild and Xcrun for packaging and automatic packaging of a logic, shell script good classmate can free play ha ...

Generate shell script instances for 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 filename. App" //Pauload directory entry after pressurization. app file name needs to be modified according to your own project   
  4. distdir= "/users/lxxx/qa" //package file storage directory
  5. version= "1.0.0"   
  6. RM-RDF "$distDir"   
  7. mkdir "$distDir" Unzip $sourceipaname //Unzip the master 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 Files   
  28. MV "${targetname}_${version}_from_${sourceid}.zip" $distDir
  29. Cd..
  30. Else   
  31. Cd.. /..
  32. Zip-r "${targetname}_${version}_from_${sourceid}.ipa" Payload //Packages for other channels   
  33. MV "${targetname}_${version}_from_${sourceid}.ipa" $distDir
  34. Fi
  35. Done RM-RDF Payload

Note: The above data.dat is also used to store all channel numbers, Sourceipaname is through the QA verification of the master package, appname for the IPA package after pressurization payload The app file name under the directory and all of the above files must be kept in the same directory as the script file and executed in the MAC environment.

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

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.