IOS local automatic packaging tool

IOS local automatic packaging tool
automatic packaging

1, why should automatic packaging tools?

Every modification of a problem, the test allows you to pack a upload fir, you want to clean -> compile package -> upload fir -> notification test. And packing is slow, it’s a waste of time. If there is a tool that can help you do all of the above things, is not it?

2, there are so many online automatic packaging tools, I downloaded directly on the line why to learn?

Yes, there are many online packaging tools, including GitHub, there are also some directly from the GitHub download and upload, but they are not necessarily suitable for you, first of all to download the configuration parameters, and does not match, the Internet is mostly for ordinary projects, but our project is managed by cocoaPods, the compiler is xxx.xcworkspace not xxx.xcodeproj. How to do, xxx.xcodeproj automatically compiled in your project directory will have xxx.app but xxx.xcworkspace can not find how to do? How to specify directories, most of these online libraries are not.

3, what preparation work?

First of all, you have to install Xcode, python3.5 (I installed version, other versions are OK), to be packaged items. Install the relevant software, just under the search can be.

End of crap, start the text. This article describes the automatic clean local projects, compile and upload fir mail notification to the relevant staff. Does not involve downloading from git. The principle is to use the python console command. Package the
iOS project

Xcode console command

Xcode console commands are basically xcodebuild to start with a few simple commands, you can try the command line.

  • Xcodebuild -version view Xcode version number and build version number
  • Xcodebuild -showsdks shows the current system of SDK, and its version
  • Xcodebuild -list first CD to the project directory to perform this command shows target Schemes, etc.

No compilation of cocoaPods items is used

If your project is an ordinary project does not use the cocoaPods then CD to the project directory directly to perform xcodebuild build, it will automatically compile the parameters are the default default build release. You can also specify the
xcodebuild -configuration debug build build will generate a build folder in your project directory, build/Release-iphoneos/xx.app
is a packaged into IPA documents required. The first build speed will be relatively slow, to compile the environment down, do not delete the build folder, build speed will be faster.

Using the compilation of the cocoaPods project

If you are unfortunate and I like the use of cocoaPods, in fact, there is nothing unfortunate, but the compiler is more trouble, first of all, or CD to the project directory. But you have to specify the compilation of documents and scheme
and also specify the location of the build folder after build, if the location can not be found, how to automatically pack IPA?.

I command here is about this:
xcodebuild -workspace xxx.xcworkspace -scheme scheme -configuration debug -derivedDataPath your ONLY_ACTIVE_ARCH=NO
so that you can specify the path to the build normal compile and we want to go to the specified directory

Package IPA

Package IPA as long as the above path is right, the package specified from the.App file path, packaged to your designated place on the line.
command:
xcrun IPhoneOS PackageApplication -v here to fill in the path specified in the.App store IPA path / file name.Ipa -o

Python implementation

The above is just to say the principle of the compiler, look at how to deal with these tasks through python.

Clean, compile, package

First create a xxx.py file, you need to understand the point of Python syntax, do not understand the direct copy code. Don’t change tab. Python syntax is strictly in accordance with the tab. I’ll put my code, you can use the
variable to change.

First you need to introduce some external dependencies. Set encoding to UTF-8

# -*- coding: UTF-8 import import sys import -*- OS time import hashlib from email import encoders from email.header import Header from email.mime.text import MIMEText from email.utils import parseaddr, formataddr import smtplib

The first step is to declare some variables

# project root directory project_path = "/Users/xx/project" # compiled.App directory app_path = "/Users/xx/project/build/Build/Products/Release-iphoneos/xxx.app" # specifies the project compiled under the directory build_path = "build" # packaged IPA storage directory targerIPA_parth = "/Users/xx/Desktop"

The second step, clean, and create a folder, here is an example of the use of the cocoaPods project, if you do not have to use the need to create a folder, the command to simplify

# clean-up project to create the directory build def (clean_project_mkdir_build): os.system ('cd%s; xcodebuild clean'% project_path) # clean project os.system ('cd%s; MKDIR build'% project_path) # create directory

%s is a placeholder for py, string type. Behind is the real filling.

Third step compile project

Def (build_project): Print (build release start) os.system ('cd%s; xcodebuild -list'os.system ('cd)%s; xcodebuild -workspace xxx.xcworkspace -scheme XXX -configuration release -derivedDataPath%s ONLY_ACTIVE_ARCH=NO Exit' ||% (project_path, build_path))

Do not know what is the xcodebuild -list scheme own check

Fourth step packing

# packaged and stored in the IPA def build_ipa (global) desktop: ipa_filename ipa_filename = time.strftime ('yourproject_%Y-%m-%d-%H-%M-%S.ipa', time.localtime (time.time) (os.system) ('xcrun) -sdk IPhoneOS PackageApplication -v%s -o%s/%s' (app_path, targerIPA_parth, ipa_filename%))

Then you can now write a method, in order to call the compiler can be packaged, the implementation will see the desktop IPA

Def (main): # clean up and create a build directory (clean_project_mkdir_build) # compile coocaPods project file and compile build_project (IPA) # package directory and set to the desktop (build_ipa)

Execution is called directly on the main ()

Upload fir

We are to upload the code to the fir test, if you use dandelion or other, please search.
through gem fir-cli install if you do not have the ruby environment, self search

When the installation is complete, enter fir in the command line. There will be a fir command prompt. We need to upload fir API_TOKEN, go to the official website of fir login can find a good fir.
get the string of characters in the variable area plus

# firm API token fir_api_token = "xxxxxxxxxxxxxxxxxxxxxxxxxx"

Then command to the IPA directory and token can upload

Def (upload_fir) # upload: if os.path.exists ("%s/%s"% (targerIPA_parth, ipa_filename)): Print ('watting... ') # directly using FIR there are problems using the absolute address in the terminal through the which fir RET = os.system ("/usr/local/bin/fir P'%s/%s' -T'%s'" (targerIPA_parth, ipa_filename, fir_api_token%)) else: print ("IPA file not found")

Here also encountered a = pit, that is, in the terminal directly behind the fir can be executed, but here can not identify the command, you must develop a full path, how to find the full path of the command it? Terminal input which fir

Send emails

Specific e-mail function to see the code, here are a few variables. I use the Sina mail sent, SMTP server, if you are POP3 please replace, but also open the corresponding service in the mailbox

From_addr = "[email protected]" password = "crusade" smtp_server = "smtp.sina.com" to_addr ='[email protected], [email protected]'

And then send e-mail

Our fir path is fixed

# mail def send_mail (MSG) = MIMEText ('xxx iOS test project arepacked, please download the test to http://fir.im/xxxxx! ','plain','utf-8') msg['From'] = _format_addr (<' automatic packaging system;%s> '% from_addr = _format_addr (msg['To'])'xxx tester <%s>'% to_addr = Header (msg['Subject'])'xxx iOS client package program ','utf-8').Encode (server) = smtplib.SMTP (smtp_server, 25) server.set_debuglevel (1 server.login) (from_addr, password) server.sendmail (from_addr, [to_addr], msg.as_string) (server.quit) ()

Then the execution sequence is like this

Def (main): # clean up and create a build directory (clean_project_mkdir_build) # compile coocaPods project file and compile build_project (IPA) # package directory and set to the desktop (build_ipa) fir (upload_fir) # # upload email (send_mail) (main) # implementation

This article focuses on the automatic packaging command, Python code can be interested in learning Python tutorial.
this code has been hosted on the GitHub: https://github.com/smalldu/autoipa
article sync on my blog: iOS local automatic packaging tool