一般使用企業(yè)證書(shū)打包的朋友可能會(huì)想到使用腳本進(jìn)行打包,因?yàn)榇虬拇螖?shù)相對(duì)普通開(kāi)發(fā)者比較多,So本人自己網(wǎng)搜一堆Python(注:本人python一竅不通)并改成所需腳本,基本可以滿足打包所需要求。
打包命令
直接上代碼:
#-*-coding:utf-8-*-
#!/usr/bin/python
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
from optparse import OptionParser
import subprocess
#import requests
import os
import shutil
import commands
#渠道文件
channellist? ? ? ? = ['渠道1','渠道2','....']
#渠道文件存放路徑
channelpath? ? ? ? = 'MultiChannels'
#渠道文件下的資源文件
filenamelist? ? ? ? = ['Info.plist','58 - Settings.png','80 - Spotlight.png','120 - iPhone.png']
#項(xiàng)目中被替換的資源文件
filepathlist? ? ? ? = ['IosClient/Info.plist','IosClient/Assets.xcassets/AppIcon.appiconset/58 - Settings.png','IosClient/Assets.xcassets/AppIcon.appiconset/80 - Spotlight.png','IosClient/Assets.xcassets/AppIcon.appiconset/120 - iPhone.png']
#項(xiàng)目名稱(chēng)
projectname? ? ? ? = 'IosClient'
#導(dǎo)出ipa文件存放路徑
OUTPUT = "/Users/xxxxx/Desktop/xxxxxx(文件夾名)"
#注:本人項(xiàng)目是cocoapods管理,因此此處路徑是xcwordsapce,否則是xcodepro路徑
WORKSAPCE = "/Users/xxxxxx/Desktop/xxxx/xxxx.xcworkspace"
#此處與項(xiàng)目保持一致
TARGET = "IosClient"
#同上
SCHEME = "IosClient"
#項(xiàng)目的配置信息
#configuration for iOS build setting
#CODE_SIGN_IDENTITY = "iPhone Distribution: xxxxxxxx Co. Ltd (xxxxxxx9A)"
#PROVISIONING_PROFILE = "xxxxxxxxxx-xxxxx-xxxxx-xxxx-xxxxxxxxxxxx"
#CONFIGURATION = "Release"
#SDK = "iphoneos"
#上傳蒲公英
# configuration for pgyer
#PGYER_UPLOAD_URL = "http://www.pgyer.com/apiv1/app/upload"
#DOWNLOAD_BASE_URL = "http://www.pgyer.com"
#USER_KEY = "5994aef875878ee001ab35900803da74"
#API_KEY = "390700ad2e15a298225e0210161438a3"
def cleanBuildDir(buildDir):
cleanCmd = "rm -r %s" %(buildDir)
process = subprocess.Popen(cleanCmd, shell = True)
process.wait()
print "cleaned buildDir: %s" %(buildDir)
# 替換文件
def replaceflies(channel):
workspacepath = os.getcwd()
srcpath = os.path.join(workspacepath, channelpath)
srcpath = os.path.join(srcpath, channel)
despath = os.path.join(workspacepath, projectname)
# 替換資源
for filename in filenamelist:
index = filenamelist.index(filename)
filepath = filepathlist[index]
srcfullpath = os.path.join(srcpath, filename)
desfullpath = os.path.join(despath, filepath)
if os.path.exists(srcfullpath):
shutil.copy(srcfullpath, desfullpath)
print "Copy '" + srcfullpath + "' to '" + desfullpath + "'."
else:
print "'" + srcfullpath + "'" + "不存在"
#def buildProject(project, target, output):
#? ? if len(CODE_SIGN_IDENTITY) and len(PROVISIONING_PROFILE):
#? ? ? ? buildCmd = 'xcodebuild -project %s -target %s -sdk %s -configuration %s build CODE_SIGN_IDENTITY="%s" PROVISIONING_PROFILE="%s"' %(project, target, SDK, CONFIGURATION, CODE_SIGN_IDENTITY, PROVISIONING_PROFILE)
#? ? ? ? print buildCmd
#? ? ? ? pass
#? ? else:
#? ? ? ? buildCmd = 'xcodebuild -project %s -target %s -sdk %s -configuration %s' %(project, target, SDK, CONFIGURATION)
#? ? ? ? print buildCmd
#
#? ? ? ? process = subprocess.Popen(buildCmd, shell = True)
#? ? ? ? process.wait()
#
#? ? ? ? signApp = "./build/%s-iphoneos/%s.app" %(CONFIGURATION, target)
#? ? ? ? signCmd = "xcrun -sdk %s -v PackageApplication %s -o %s" %(SDK, signApp, output)
#? ? ? ? process = subprocess.Popen(signCmd, shell=True)
#? ? ? ? (stdoutdata, stderrdata) = process.communicate()
#
#? ? ? ? #? ? ? ? uploadIpaToPgyer(output)
#? ? ? ? cleanBuildDir("./build")
def buildWorkspace(workspace, scheme, output, i):
process = subprocess.Popen("pwd", stdout=subprocess.PIPE)
(stdoutdata, stderrdata) = process.communicate()
buildDir = stdoutdata.strip() + '/build'
print "buildDir: " + buildDir
if len(CODE_SIGN_IDENTITY) and len(PROVISIONING_PROFILE):
buildCmd = 'xcodebuild -workspace %s -scheme %s -sdk %s -configuration %s build CODE_SIGN_IDENTITY="%s" PROVISIONING_PROFILE="%s" SYMROOT=%s' %(workspace, scheme, SDK, CONFIGURATION,CODE_SIGN_IDENTITY, PROVISIONING_PROFILE, buildDir)
print buildCmd
pass
else:
buildCmd = 'xcodebuild -workspace %s -scheme %s -sdk %s -configuration %s SYMROOT=%s' %(workspace, scheme, SDK, CONFIGURATION, buildDir)
print buildCmd
process = subprocess.Popen(buildCmd, shell = True)
process.wait()
signApp = "./build/%s-iphoneos/%s.app" %(CONFIGURATION, scheme)
signCmd = "xcrun -sdk %s -v PackageApplication %s -o %s" %(SDK, signApp, output+"/"+str(i)+".ipa")
process = subprocess.Popen(signCmd, shell=True)
(stdoutdata, stderrdata) = process.communicate()
cleanBuildDir(buildDir)
def main(argvs):
if len(argvs) < 2:
print "至少輸入一個(gè)渠道名稱(chēng)"
return
else:
for i in xrange(1,len(argvs)):
channel = argvs[i]
print len(argvs)
print argvs
if not channel in channellist:
print "沒(méi)有此渠道名稱(chēng)"
else:
#? ? ? ? ? ? ? ? pass
replaceflies(channel)
buildWorkspace(WORKSAPCE, SCHEME, OUTPUT,i)
if __name__ == '__main__':
main(sys.argv)
------------------------------腳本結(jié)束-------------------------------------
調(diào)用方法:
終端命令輸入:
1.把build.py 放在與項(xiàng)目文件同一級(jí)文件目錄下
2. cd 項(xiàng)目存在的文件路徑?
3.python build.py 渠道1 渠道2?
?大功告成就會(huì)發(fā)現(xiàn) output路徑下會(huì)出現(xiàn)1.ipa文件可自行選擇上傳。