IOS command line automation integrated package full record (multiple target, multiple environments)

Recently, the company wants to integrate the packaging test, packaging on-line process. Want to achieve rapid iOS out.

Our company has adopted the jenkins+fir. principle to achieve the automatic warehouse Git to pull the latest code, and then downloaded to the specified one apple computer, and then uploaded to the server after finished packing for testing and maintenance personnel to download.

Because our company is on the development of Jenkins on Java, on this I will not repeat.

1 company project analysis:

– our company has a total of three products: XXX gold service, XXX gold service professional edition, XXX gold service version. These three products share the same code, but the picture material is not the same, so it is in the same project.

Packaging environment: develop (Development) test (test) production (online) local (local)

– now let’s sort out: three products, four environments. This means that there are 12 situations that need to be distinguished from the command line.

2 solution:

– solution: by different target to distinguish between different versions, through different configuration to distinguish between different environment configuration and key.

–xcodebuild command can be packaged in the Xcode command line, the command can then enter the terminal man xcodebuild view, or directly to the apple official documents I point my point.

–xcodebuild archive is a packaged command, which has a parameter that is -configuration it corresponds to the following parameters:

IOS command line automation integrated package full record (multiple target, multiple environments)

– we can specify the parameters of -configuration and -scheme to implement different environments and versions. Initial default configuration Debug and Release only two cases. We can add.Xcconfig files by adding different configuration.

3 integration process:

3.1. create multiple target, reference picture resources optimization:

– prior to our company’s three products are shared a set of code, sharing a target, I am in each package when you manually modify the picture material as well as bundle ID, displayName, etc.. This labor cost is too large, and error prone. And three different versions of the command line packaging is more difficult to achieve, so I used the Target corresponding to the three projects of the three. Copy the other two target as shown below, and then change the use of the material library.

– but there is a problem, that is, I need to put three sets of images in the Assets.xcassets file, and then the code to determine the internal bundle ID to select different material. This leads to the problem is to lead out of the IPA package from the original 29M into 45M. because of the time of the.Xcassets link material too much achive.

– now create three versions of the corresponding Assets.xcassets file, as shown in figure:

IOS command line automation integrated package full record (multiple target, multiple environments)

– three versions of the same material on the Assets.xcassets, different in the corresponding file, Normal (Standard Edition), Pro (Professional Edition), Nat (activity)

– in the three version of target, in copy bundle resource only add the corresponding.Xcassets file and Assets.xcassets on it.

IOS command line automation integrated package full record (multiple target, multiple environments)

– once again, you’ll find that IPA is back to its size. Similarly configure the remaining two target.

The increase of 3.2. 15.Xcconfig files

– we need a total of 1.Debug 2.Release 4.Local 5.Test five configuration, as shown in figure 3.Adhoc.

IOS command line automation integrated package full record (multiple target, multiple environments)

– according to the project, each configuration file contains the same key value, as follows:

#include “Pods/Target Support Files/Pods-zkp/Pods-zkp.debug.xcconfig” baseurl REQUEST_BASE_URL = / / network request @ AGREEMENT_BASE_URL = “http:////xxxx/resource/” @ “http:////xxxx/resource/product/agrHtml? PrdCode=” H5_BASE_URL “http:////xxxx” SECRET = = @ @ @ = “XXXXXX” CLIENTID “xxxxx” //App APPSCHEM = “cn.com.xxx.zkp” = APPID @ @ XXXXXX @ Au / / UmengAppkey = “xxxxxxxxxxxxxxxxxxx configuration” / / Baidu statistics BaiduMobKey = “xxxxxxxxxxxxxxx” / / WeChat @ WeChatKey = @ @ = “XXXXXXXXXXXXX” WeChatSecret “xxxxxxxxxxxxxxxxxxxx” #include “../ZKPGenerator.xcconfig”

– you can include other profiles in the configuration file, where the contents of the Generator.xcconfig file are:

GCC_PREPROCESSOR_DEFINITIONS = $(inherited) ZKPPrefix=’$(REQUEST_BASE_URL) ZKPAgreement=’$(AGREEMENT_BASE_URL) ‘WebViewBaseURL=’$’ (H5_BASE_URL) ‘UmengAppkey=’$’ (UmengAppkey) WeChatKey=’$(WeChatKey) WeChatSecret=’$'(WeChatSecret)’ BaiduMobKey=’$'(BaiduMobKey) CLIENTID=’$(CLIENTID) SECRET=’$(SECRET)’ APPSCHEM=’$'(APPSCHEM)’ APPID=’$'(APPID)

– the function is to define the constants defined in the configuration file as a pre compiled macro to facilitate access to the code. Somewhat similar to our project in which the PCH file GCC_PREPROCESSOR_DEFINITIONS, the document is as follows:

Space-separated list of option specifications. Specifies preprocessor macros in the form foo (for a simple #define (or) foo=1 for a value definition This list is). Passed to the compiler through the GCC -D option when compiling precompiled headers and implementation files.

–GCC_PREPROCESSOR_DEFINITIONS is the GCC precompiled header parameter, usually we can Build the Project file

Settings defaults to the precompiled macro definition. The path under Xcode is Build Settings-> Apple LLVM 8

-Preprocessing-> Preprocessor Macros

– notes:

1&gt. Here to pay attention to the translation of the domain name: http:////xxxx/xxxx/ can not be written as http://xxxx/xxxx/, because the default will be the contents of the comments behind the http.

2> however, after translation, there is a warning when compiling the project. Because the Xcode warning mechanism does not recognize the translation, and often there will be hundreds of warnings, because the domain macro all network requests will be used. Following figure:

IOS command line automation integrated package full record (multiple target, multiple environments)

3> solution ignored warnings. Right warning -> Reveal in Log

IOS command line automation integrated package full record (multiple target, multiple environments)

4> here is the description of this warning, which will be ignored after entering the build setting after replication

IOS command line automation integrated package full record (multiple target, multiple environments)

5&gt. Build setting search in other warning, the warning signs will be written and separated. As follows: -Wunknown-escape-sequence

-W is a prefix, if you want to ignore the need to add to -Wno-unknown-escape-sequence, save, re compile, is not found on the warning disappeared

IOS command line automation integrated package full record (multiple target, multiple environments)

3.3. create 5 kinds of configuration – – – – – –

– create configuration, add the corresponding 5 kinds of configuration, when adding Adhoc is copy from Release, the rest are copy from Debug

IOS command line automation integrated package full record (multiple target, multiple environments)

– modify the.Xcconfig file in the macro to pay special attention to the cache, often after the modification is also used before the value. This time Xcode clean is useless.

– solution: delete the cache in DerivedData, and then restart xcode.

IOS command line automation integrated package full record (multiple target, multiple environments)

– add the newly created.Xcconfig file

IOS command line automation integrated package full record (multiple target, multiple environments)

The 3.4. configuration description file and certificate

– computer and Xcode configuration corresponding certificate and description file: This is basically done, and then the corresponding configuration Certificate in the developer background:

3.4.1. certificate:

1> development certificate.

2> release certificate.

3.4.2. description file:

1> development. (to run real), the corresponding development certificate

2>.Adhoc Certificate (used to install the test suite for testing), the corresponding certificate issued

. 3> issuing certificates (released to App Store), the corresponding certificate issued

– after installation, the Xcode configuration is complete.

3.5. command

3.5.1.cd to code directory

3.5.2. start packing

Xcodebuild archive -workspace zkp.xcworkspace -configuration Adhoc -scheme zkp -archivePath zkp.xcarchive CODE_SIGN_IDENTITY= iPhone Distribution: XXXXXXXX (yyyyyyy) PROVISIONING_PROFILE_SPECIFIER= “xxxxxxx””

1> corresponding parameter configuration

The -workspace project file name (with cocopods integrated project, if not the whole -xcodeproj for zkp.xcodeproj -configuration) corresponding to the name of the path CODE_SIGN_IDENTITY development environment configuration, the certificate is compile time execution mode -scheme specified by scheme target -archivePath derived from different.Xcarchive name PROVISIONING_PROFILE_SPECIFIER description file

3.5.3. export IPA

Xcodebuild -exportArchive zkpPro.xcarchive -exportPath professional -exportFormat IPA -exportProvisioningProfile xxxxxxx -archivePath ~/Desktop/

1> corresponding parameter configuration

-archivePath.Xcarchive file path -exportPath export IPA path -exportProvisioningProfile description file name (and above)

3.5.4. summary:

–iOS will sign at the time of archive, and then exported again for signature verification, here and Android are different, when Android package will not be signed, in the export when signing. So iOS in the package, and export to specify the signature.

– the above order is the author of their own sort out, pro test effective, there are questions welcome comments. The Xcode can no longer be specified inside a certificate, because more than one person, if other developers accidentally changed, no nonsense.

– the last xcodebuild command line has a hole in the package, the first time to pull down the code from the warehouse, the project is not open before the implementation of xcodebuild

–achive command will be stuck in the scene below. But if the project has been opened will not be stuck, achive will succeed.

IOS command line automation integrated package full record (multiple target, multiple environments)

– the reason is because the scheme file does not exist. The scheme file is stored in the xcuserdata folder, the project did not open before the xcuserdata file is not content, the default will be generated after opening. But the xcodebuild tool will not be stuck in the execution of the archive.

– solution:

1> select manager scheme

IOS command line automation integrated package full record (multiple target, multiple environments)

2> select shared scheme

IOS command line automation integrated package full record (multiple target, multiple environments)

– then you can pack it up.

– so far on the CI automation package, on the iOS side needs to be configured to complete the work. Because the interior is more than target, and have quite much of the pit, hereby summary.