IOS automatic signature packing (xcodebuild)

IOS automatic packaging with xcodebuild command, the terminal input xcodebuild –help can view the parameters of xcodebuild.

Xcodebuild concrete syntax:

  • No workspace engineering xcodebuild name.xcodeproj] [[-target [-project targetname]… -alltargets] [-configuration configurationname] [-sdk [sdkfullpath | | sdkname]] [action… [[buildsetting=value]… [[-userdefault=value]… Xcodebuild [-project -scheme schemename [[-destination name.xcodeproj] destinationspecifier]… Value] [-configuration configurationname] [-sdk [sdkfullpath [-destination-timeout sdkname]] [action |… [[buildsetting=value]… [[-userdefault=value]… ]

Some parameters can be added to the command to configure different environments when the command is executed. For example, if you want to archive out of the Debug environment package, then you can add the command -configuration Debug parameters. You can also specify the Profile file for the UUID file to be signed by adding the PROVISIONING_PROFILE parameter.

  • For workspace based projects, such as the cocoapods project, the script format is as follows: xcodebuild -workspace -scheme schemename [[-destination destinationspecifier]… Value] [-configuration configurationname] [-sdk [sdkfullpath [-destination-timeout sdkname]] [action |… [[buildsetting=value]… [[-userdefault=value]… ]

Of course, there are a lot of optional parameters, which are not listed in one, if you are interested can be viewed by xcodebuild –help.

Shell script (project is not WorkSpace)

Script download path: GitHub Download

#author by note: effective # script directory and xxxx.xcodeproj to be in the same directory, any other directory, please modify the script. # project name (Target name) Project_Name= "Target name, the system default and project name" # configuration environment, Release or Debug Configuration= "Release" #AdHoc version of the Bundle ID AdHocBundleID= "com.xxx" #AppStore version of the Bundle ID AppStoreBundleID= "com.xxx" #enterprise Bundle ID "EnterpriseBundleID= com.xxx ADHOC" # # certificate name # description file ADHOCCODE_SIGN_IDENTITY= "iPhone Distribution: XXXX" ADHOCPROVISIONING_PROFILE_NAME= "xxxx-xxxx-xxxx-xxxx" #AppStore certificate name # description file APPSTORECODE_SIGN_IDENTITY= "iPhone Distribution: XXXX" APPSTOREROVISIONING_PROFILE_NAME= "xxxx-xxxx-xxxx-xxxx" # enterprise (enterprise) certificate name description file "iPhone Distribution: ENTERPRISECODE_SIGN_IDENTITY= # xxxxx" ENTERPRISEROVISIONING_PROFILE_NAME= "xxxx-xxxx-xxxx-xxxx" # loading all versions of plist AppStoreExportOptionsPlist=./AppStoreExportOptionsPlist.plist EnterpriseExportOptionsPlist=./EnterpriseExportOptionsPlist.plist ADHOCExportOptionsPlist=${ADHOCExportOptionsPlist} AppStoreExportOptionsPlist=${AppStoreExportOptionsPlist} file ADHOCExportOptionsPlist=./ADHOCExportOptionsPlist.plist EnterpriseExportOptionsPlist=${EnterpriseExportOptionsPlist} echo "~~~~~~~~~~~~ selection package (input number) ~~~~~~~~~~~~~~~" echo "1 Appstore" echo "adhoc 2" echo "3 enterprise" # read user input variables in read parameter sleep to the coexistence of 0.5 method= "$parameter" # interpretation of whether the user has input if [-n] then "$method" #clean xcodebuild clean -xcodeproj./$Project_Name/$Project_Name.xcodeproj -configuration $Configuration -alltargets if ["$method"] = "1" then #appstore -project $Project_Name.xcodeproj -scheme $Project_Name -configuration script xcodebuild $Configuration -archivePath build/$Project_Name-appstore.xcarchive clean archive build CODE_SIGN_IDENTITY= "${APPSTORECODE_SIGN_IDENTITY}" PROVISIONING_PROFILE= "${APPSTOREROVISIONING_PROFILE_NAME}" PRODUCT_BUNDLE_IDENTIFIER= "${AppStoreBundleID}" xcodebuild -exportArchive -archivePath build/$Project_Name-appstore.xcarchive -exportOptionsPlist $AppStoreExportOptionsPlist -exportPath ~/Desktop/$Project_Name-appstore.ipa elif ["$method"] = "2" then #adhoc xcodebuild -project $Project_Name.xcodeproj -scheme script $Project_Name -configuration $Configuration -archivePath build /$Project_Name-adhoc.xcarchive clean archive build CODE_SIGN_IDENTITY= "${ADHOCCODE_SIGN_IDENTITY}" PROVISIONING_PROFILE= "${ADHOCPROVISIONING_PROFILE_NAME}" PRODUCT_BUNDLE_IDENTIFIER= "${AdHocBundleID}" xcodebuild -exportArchive -archivePath build/$Project_Name-adhoc.xcarchive -exportOptionsPlist $ADHOCExportOptionsPlist -exportPath ~/Desktop/$Project_Name-adhoc.ipa elif ["$method"] = "3" then xcodebuild -project $Project_Name.xcodeproj # enterprise package script -scheme $Project_Name -configuration $Configuration -archivePath build/$Project_Name-enterprise.xcarchive clean archive build CODE_SIGN_IDENTITY= "${ENTERPRISECODE_SIGN_IDENTITY}" PROVISIONING_PROFILE= "${ENTERPRISEROVISIONING_PROFILE_NAME}" PRODUCT_BUNDLE_IDENTIFIER= "${EnterpriseB UndleID} "xcodebuild -exportArchive -archivePath build/$Project_Name-enterprise.xcarchive -exportOptionsPlist $EnterpriseExportOptionsPlist -exportPath ~/Desktop/$Project_Name-enterprise.ipa else echo" parameter is invalid. "Exit 1 fi fi...

Note: 1 due to the script configuration path problem, so xcodebuild.sh and xxx.xcodeproj in the same directory, or there will be a path problem. As shown in Figure:

IOS automatic signature packing (xcodebuild)
script directory and works in the same directory

2 because the Xcode8 can automatically configure the certificate in Project-> General, so use the script to remove the function before packing. As shown in Figure:

IOS automatic signature packing (xcodebuild)
remove automatic configuration certificate

3 configuration script, you need to configure the information as shown below, you can not need to configure the version. For example, only need AppStore IPA, you only need to configure the AppStore version of the relevant configuration.

IOS automatic signature packing (xcodebuild)
configuration script

4 execute the script, open the terminal, CD to the current script where the path, and then perform:./xcodebuild.sh.
5 export of the IPA package to save the default desktop, save the current directory if you need to modify, you can modify the script. As shown in the figure, for example, my project name is OneProject, then the package as follows:

IOS automatic signature packing (xcodebuild)
IPA package folder

Open the folder is the IPA package, as shown in Figure:

IOS automatic signature packing (xcodebuild)
IPA package

6 how to view the certificate name and configuration file UUID?
open key access, find the certificate, click on the display profile, there is a common name, copy to the script, as shown in Figure:

IOS automatic signature packing (xcodebuild)
certificate
IOS automatic signature packing (xcodebuild)
commonly used name

Profile UUID can be viewed in Xcode, Xcode-> Preferences; -> Accounts, as shown below:

IOS automatic signature packing (xcodebuild)
click View Details
IOS automatic signature packing (xcodebuild)
click Show in Finder
IOS automatic signature packing (xcodebuild)
configuration file UUID

The profile name above is 6994F55C-1960-4EF9-AA7E-9C1FABDBA7A8.mobileprovision. The configuration file UUID is 6994F55C-1960-4EF9-AA7E-9C1FABDBA7A8. So copy 6994F55C-1960-4EF9-AA7E-9C1FABDBA7A8 to script.

Execute script

Open the terminal, CD to the current script where the path, in the terminal input:./xcodebuild.sh, click enter.

WorkSpace script

If your project uses workspace, or cocoapods, then the above script does not apply, the specific script is as follows, the script configuration is the same as above.
script download path: GitHub Download

#author by note: effective # script directory and WorkSpace directory in the same directory # project name (Target name) Project_Name= "Target system is equal to the project name, the default name of" #workspace "in the name of the Workspace_Name= WorkSpace name" # configuration environment, Release or Debug, the default release Configuration= "Release" #AdHoc ID AdHocBundleID= "version of the Bundle com.xxxx #AppStore version of the Bundle ID AppStoreBundleID=" com.xxxx "#enterprise Bundle ID" EnterpriseBundleID= com.xxxx ADHOC "# certificate name" iPhone Distribution: ADHOCCODE_SIGN_IDENTITY= # description file XXXX "ADHOCPROVISIONING_PROFILE_NAME=" xxxxx-xxxx-xxxx-xxxx-xxxxxx "#AppStore certificate name # description file" iPhone APPSTORECODE_SIGN_IDENTITY= Distribution: "xxxxx-xxxx-xxxx-xxxx-xxxxxx APPSTOREROVISIONING_PROFILE_NAME= xxxxx"" # enterprise (enterprise) certificate name # description file "iPhone Distribution: ENTERPRISECODE_SIGN_IDENTITY= XXXX" ENTERPRISEROVISIONING_PROFILE_NAME= "xxxxx-xxxx-xxx-xxxx" # loading all versions of plist AppStoreExportOptionsPlist=./AppStoreExportOptionsPlist.plist EnterpriseExportOptionsPlist=./EnterpriseExportOptionsPlist.plist ADHOCExportOptionsPlist=${ADHOCExportOptionsPlist} AppStoreExportOptionsPlist=${AppStoreExportOptionsPlist} EnterpriseExportOptionsPlist=${EnterpriseExportOptionsPlist} ADHOCExportOptionsPlist=./ADHOCExportOptionsPlist.plist file echo "~~~~~~~~~~~~ selection package (input number) ~~~~~~~~~~~~~~~" echo "1 adHoc" echo "AppStore 2" echo "3 Enterprise" # read user input the coexistence of the variable 0.5 method= "$par read parameter sleep Ameter "# interpretation of whether the user has input if [-n $method] then if [" $method "=" 1 "then #adhoc xcodebuild -workspace $Workspace_Name.xcworkspace] -scheme $Project_Name script -configuration $Configuration -archivePath build/$Project_Name-adhoc.xcarchive clean archive build CODE_SIGN_IDENTITY=" ${ADHOCCODE_SIGN_IDENTITY} "PROVISIONING_PROFILE=" ${ADHOCPROVISIONING_PROFILE_NAME} "PRODUCT_BUNDLE_IDENTIFIER=" ${AdHocBundleID} "xcodebuild -exportArchive -archivePath build /$Project_Name-adhoc.xcarchive -exportOptionsPlist ${ADHOCExportOptionsPlist} -exportPath ~/Desktop/$Project_Name-adhoc.ipa elif" [2] "$method" = "then #appstore xcodebuild -workspace $Workspace_Name.xcworkspace -scheme $Project_Name -configuration script $Con Figuration -archivePath build/$Project_Name-appstore.xcarchive archive build CODE_SIGN_IDENTITY= "${APPSTORECODE_SIGN_IDENTITY}" PROVISIONING_PROFILE= "${APPSTOREROVISIONING_PROFILE_NAME}" PRODUCT_BUNDLE_IDENTIFIER= "${AppStoreBundleID}" xcodebuild -exportArchive -archivePath build/$Project_Name-appstore.xcarchive -exportOptionsPlist ${AppStoreExportOptionsPlist} -exportPath ~/Desktop/$Project_Name-appstore.ipa elif ["$method"] = "3" then xcodebuild -workspace $Workspace_Name.xcworkspace # enterprise package script -scheme $Project_Name -configuration $Configuration -archivePath build/$Project_Name-enterprise.xcarchive archive build CODE_SIGN_IDENTITY= "${ENTERPRISECODE_SIGN_IDENTITY}" PROVISIONING_PROFILE= "ENTERPRISEROVISIONING_PROFILE_ a. NAME} "PRODUCT_BUNDLE_IDENTIFIER=" ${EnterpriseBundleID} "xcodebuild -exportArchive -archivePath build/$Project_Name-enterprise.xcarchive -exportOptionsPlist ${EnterpriseExportOptionsPlist} -exportPath ~/Desktop/$Project_Name-enterprise.ipa else echo" parameter is invalid. "Exit 1 fi fi...

Possible problems

1 if the configuration of the certificate name, BundleID, configuration file UUID is not the same, the script will be wrong, this can look at the script error, because the error is very obvious, so it is not in the screenshot.
2 if the script executes the following error in the terminal input: RVM system, enter the.

IOS automatic signature packing (xcodebuild)

3 -bash:./xx.sh: Permission denied if the process of execution of the script, said permission issues, so in the terminal execution: Chmod 777 xx.sh, then you can enter, but to note that Chmod 777 is behind the script path.

supplement

The above script default startup Bitcode, if your project does not open Bitcode, you can add a few plist files in the top two key pairs, namely: uploadBitcode=NO, compileBitcode=NO