Using Fastlane gym/xctool to write IPA packaging scripts

2017/02/27 update,
, Fastlane update, unified the use of various tools, the article made the corresponding command update

The script listed in the 2016/04/21 update is also updated to https://github.com/xilin/ios-build-script in

2016/03/14 update

Packaged using Fastlane gym

  1. Install gym https://github.com/fastlane/fastlane gym, using the latest API packaging, faster, more concise design, smart, you need to install ruby, and then execute sudo gem install Fastlane
  2. The new script no longer needs to manually specify provisioning profile, and the package kernel command changes from the three line to the line
#! /bin/bash # chronograph SECONDS=0 # script project_path=$placed in the path with the same project (PWD) # take the current time string is added to the end of the file now=$(date +%Y_%m_%d_%H_%M_%S) # scheme specifies the project name scheme= "DemoScheme" configuration= "to specify the configuration # packaged Adhoc" # specified output package use, currently supports app-store, package, ad-hoc, enterprise, development, and developer-id, xcodebuild method export_method='ad-hoc'# parameters specified project address workspace_path= "$project_path/Demo.xcworkspace" # specifies the output path output_path= "/Users/your_username/Documents/" # output file address archive_path= "$output_path/Demo_${now}.xcarchive" ipa_path= "IPA # output address $output_path/ Demo_${now}.ipa" # designated transport The IPA name ipa_name= "Demo_${now}.ipa" # obtained during the execution of the command commit message commit_msg= "$1" # output variables "===workspace path: ${workspace_path}===" echo echo "===archive path: ${archive_path}===" echo "===ipa path: echo" ===export method: a. ipa_path}=== "${export_method}===" echo "===commit msg: $1===" # first empty before a build Fastlane gym --workspace ${workspace_path} --scheme ${scheme} --clean --configuration ${configuration} --archive_path ${archive_path} --export_method ${export_method} --output_directory ${output_path} --output_name ${ipa_name} fir publish ${ipa_path} # uploaded to fir -T fir_token -c "${commit_msg}" # output in echo "===Finished. Total time: ${SECONDS}s==="

target

  • For a Xcode project that uses CocoaPods for dependency management, write a script to automatically package IPA files and upload them to fir.

Preparation environment

  1. Installing xctool https://github.com/facebook/xctool xctool is an enhanced implementation of the official xcodebuild, and the output is much more intuitive and readable than xcodebuild, and you can install brew install xctool through brew
  2. The command line tools that install fir-cli fir need to install Ruby first and then execute gem install fir-cli

Some concepts

  1. The *.workspace file
    uses the CocoaPods managed project to generate the workspace file after the execution of the pod install
  2. The scheme
    displays in the upper left corner of the Xcode, the right side of the run icon, and the left of the device selection
  3. Configuration
    select items in Xcode, Info tab will list all the configuration, generally have Debug and Release two kinds
  4. Provisioning profile
    selects target in Xcode, searches Provisioning Profile under Build Settings tab, defaults to Automatic, and clicks on all the names that are available in the drop-down list

Scripting steps

  1. Cleanup project
  2. Generating Archive
  3. Export IPA
  4. Upload to fir

Final script

#! /bin/bash # chronograph SECONDS=0 # script project_path=$placed in the path with the same project (PWD) # take the current time string is added to the end of the file now=$(date +%Y_%m_%d_%H_%M_%S) # scheme specifies the project name scheme= "DemoScheme" configuration= "to specify the configuration # packaged Adhoc" # designated packing used the provisioning profile provisioning_profile='AdHoc Profile'# specified project name address workspace_path= "$project_path/Demo.xcworkspace" output_path= "/Users/ # specifies the output path specified output file your_username/Documents/" # address archive_path= "$output_path/Demo_${now}.xcarchive" # specified output IPA address ipa_path= "$output_path/Demo_${now}.ipa" # obtained during the execution of the command commit message commit_msg= "$1" # output set variable value echo ===works Pace path: ${workspace_path}=== "echo" ===archive path: ${archive_path}=== "echo" ===ipa path: ${ipa_path}=== "echo" ===profile: ${provisioning_profile}=== "echo" ===commit msg: $1=== "# first empty before a build xctool clean -workspace workspace_path} -scheme ${scheme} -configuration ${configuration} # A. according to the specified project, scheme, configuration and archive xctool file package output path build -workspace ${workspace_path} -scheme ${scheme} -configuration ${configuration} archive -archivePath ${archive_path} # using the specified provisioning profile derived IPA # I temporarily did not find the specified provisioning profile xctool method, the xcodebuild xcodebuild -exportArchive -archivePath ${archive_path} -exportPath ${ipa_path} -exportFormat IPA -exportProvisioningProfile "${provisioning_profile}" fir fir publish # uploaded to the ${ipa_path} -T fir_token -c "${commit_msg}" # output in echo "===Finished. Total time: ${SECONDS}s==="

Refer

  • Http://datacalculation.blogspot.in/2014/10/making-ad-hoc-build-from-command-line.html
  • Https://github.com/facebook/xctool
  • Https://github.com/FIRHQ/fir-cli