使用Python和shell脚本打包ipa

释放双眼,带上耳机,听听看~!

autobuild.py打包单个ipa的Python文件,TestBuild.sh打包多个ipa的shell文件,将这两个文件放到工程根目录,就可在终端中用命令打包。

autobuild.py参数说明:
-p 工程project
-w 工作空间workspace
-t target
-s scheme
-c configuration,即Debug/Release/自定义configuration,如果不设置,默认使用Release
-d definitions,预编译宏,如果设置了这个,将覆盖掉Xcode工程build setting里的预编译宏
-o 输出的ipa文件路径

注意:
1.autobuild.py没有实现签名,需要保证Xcode工程中设置好了证书
2.如果打包workspace,需指定-w和-s;如果打包project,需指定-p和-t
3.-c和-d非必传

autobuild.py


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
1from optparse import OptionParser
2import subprocess
3
4#configuration for iOS build setting
5SDK = "iphoneos"
6
7def cleanBuildDir(buildDir):
8    cleanCmd = "rm -r %s" %(buildDir)
9    process = subprocess.Popen(cleanCmd, shell = True)
10    process.wait()
11    print "cleaned buildDir: %s" %(buildDir)
12
13def buildProject(project, target, configuration, definitions, output):
14    if definitions is None:
15        buildCmd = 'xcodebuild -project %s -target %s -sdk %s -configuration %s build' %(project, target, SDK, configuration)
16    else:
17        buildCmd = 'xcodebuild -project %s -target %s -sdk %s -configuration %s GCC_PREPROCESSOR_DEFINITIONS="%s" build' %(project, target, SDK, configuration, definitions)
18    process = subprocess.Popen(buildCmd, shell = True)
19    process.wait()
20
21    signApp = "./build/%s-iphoneos/%s.app" %(configuration, target)
22    signCmd = "xcrun -sdk %s -v PackageApplication %s -o %s" %(SDK, signApp, output)
23    process = subprocess.Popen(signCmd, shell=True)
24    (stdoutdata, stderrdata) = process.communicate()
25
26    cleanBuildDir("./build")
27
28def buildWorkspace(workspace, scheme, configuration, definitions, output):
29    process = subprocess.Popen("pwd", stdout=subprocess.PIPE)
30    (stdoutdata, stderrdata) = process.communicate()
31    buildDir = stdoutdata.strip() + '/build'
32    print "buildDir: " + buildDir
33    if definitions is None:
34        buildCmd = 'xcodebuild -workspace %s -scheme %s -sdk %s -configuration %s build SYMROOT=%s' %(workspace, scheme, SDK, configuration, buildDir)
35    else:
36        buildCmd = 'xcodebuild -workspace %s -scheme %s -sdk %s -configuration %s GCC_PREPROCESSOR_DEFINITIONS="%s" build SYMROOT=%s' %(workspace, scheme, SDK, configuration, definitions, buildDir)
37    process = subprocess.Popen(buildCmd, shell = True)
38    process.wait()
39
40    signApp = "./build/%s-iphoneos/%s.app" %(configuration, scheme)
41    signCmd = "xcrun -sdk %s -v PackageApplication %s -o %s" %(SDK, signApp, output)
42    process = subprocess.Popen(signCmd, shell=True)
43    (stdoutdata, stderrdata) = process.communicate()
44
45    cleanBuildDir(buildDir)
46
47def xcbuild(options):
48    project = options.project
49    workspace = options.workspace
50    target = options.target
51    scheme = options.scheme
52    output = options.output
53    configuration = options.configuration
54    definitions = options.definitions
55    if configuration is None:
56        configuration = "Release"
57    if project is None and workspace is None:
58        pass
59    elif project is not None:
60        buildProject(project, target, configuration, definitions, output)
61    elif workspace is not None:
62        buildWorkspace(workspace, scheme, configuration, definitions, output)
63
64def main():
65
66    parser = OptionParser()
67    parser.add_option("-w", "--workspace", help="Build the workspace name.xcworkspace.", metavar="name.xcworkspace")
68    parser.add_option("-p", "--project", help="Build the project name.xcodeproj.", metavar="name.xcodeproj")
69    parser.add_option("-s", "--scheme", help="Build the scheme specified by schemename. Required if building a workspace.", metavar="schemename")
70    parser.add_option("-t", "--target", help="Build the target specified by targetname. Required if building a project.", metavar="targetname")
71    parser.add_option("-o", "--output", help="specify output filename", metavar="output_filename")
72    parser.add_option("-c", "--configuration", help="Build the configuration specified by configurationname", metavar="configurationname")
73    parser.add_option("-d", "--definitions", help="gcc preprocessor definitions", metavar="definitions")
74    (options, args) = parser.parse_args()
75
76    print "options: %s, args: %s" % (options, args)
77
78    xcbuild(options)
79
80if __name__ == '__main__':
81    main()
82

TestBuild.sh


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1#!/bin/sh
2#-p 工程project
3#-w 工作空间workspace
4#-t target
5#-s scheme
6#-c configuration
7#-d definitions,预编译宏
8#-o 输出文件
9
10python autobuild.py -p TestBuild.xcodeproj -t TestBuild -o ~/Desktop/TestBuild_Release.ipa
11python autobuild.py -p TestBuild.xcodeproj -t TestBuild -c Release_Test -o ~/Desktop/TestBuild_Release_Test.ipa
12#预编译宏示例
13python autobuild.py -p TestBuild.xcodeproj -t TestBuild -c Release -d "DEBUG_SERVER=0 CHANNEL=\\@\\\\\\\"channel1\\\\\\\"" -o ~/Desktop/TestBuild_Release_channel1.ipa
14python autobuild.py -p TestBuild.xcodeproj -t TestBuild -c Release_Test -d "DEBUG_SERVER=1 CHANNEL=\\@\\\\\\\"channel1\\\\\\\"" -o ~/Desktop/TestBuild_Release_Test_channel1.ipa
15
16

给TA打赏
共{{data.count}}人
人已打赏
安全技术

c++ list, vector, map, set 区别与用法比较

2022-1-11 12:36:11

安全技术

电子邮件永存 安全的本质是人

2016-12-29 13:01:28

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索