最近看了下命令行打包,发现网上文章不全,所以总结了下。
- 1 进入项目路径
cd /Users/chentao/Desktop/safeBoxApp/DamoApp - 2 清除
xcodebuild clean -project /Users/chentao/Desktop/safeBoxApp/DamoApp/DamoApp.xcodeproj -configuration ${CONFIGURATION} -alltargets - 2 archive 生成xcarchive文件
xcodebuild archive -project /Users/chentao/Desktop/safeBoxApp/DamoApp/DamoApp.xcodeproj -scheme DamoApp -archivePath bin/DamoApp.xcarchive - 3 根据相关配置的plist文件导出相关的ipa包
xcodebuild -exportArchive -archivePath /Users/chentao/Desktop/safeBoxApp/DamoApp/bin/DamoApp.xcarchive -exportPath /Users/chentao/Desktop/safeBoxApp/DamoApp/DamoApp.a -exportOptionsPlist /Users/chentao/Desktop/safeBoxApp/DamoApp/ExportOptions_adoc.plist
上述内容中 DamoApp是我项目的名字,ExportOptions_adoc.plist 是相关的配置内容。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>compileBitcode</key>
<false/>
<key>method</key>
<string>enterprise</string>
<key>provisioningProfiles</key>
<dict>
<key>com.safeBox.keychan</key>
<string>SafeBoxInhouseCer</string>
</dict>
<key>signingCertificate</key>
<string>iPhone Distribution</string>
<key>signingStyle</key>
<string>manual</string>
<key>stripSwiftSymbols</key>
<true/>
<key>teamID</key>
<string>37DS582758</string>
<key>thinning</key>
<string><none></string>
</dict>
</plist>
打包的方式基本有四种,对应的plist文件的一些参数也会不一样
上架appstore:
method = app-store, compileBitcode = YES, uploadSymbols = YES;
企业证书包(企业内部使用):
method = enterprise,compileBitcode = NO;
adoc包;
method = enterprise,compileBitcode = NO;
develope 包:
method = development,compileBitcode = NO;
请注意:项目证书所需手动配置。
随后发现一行行敲打指令很麻烦,就写了个python脚本代码如下:
#!/usr/bin/env python
import subprocess
def arriveProject():
archiviCmd ="cd /Users/chentao/Desktop/safeBoxApp/DamoApp";
process = subprocess.Popen(archiviCmd,shell = True);
process.wait()
archivieReturnCode = process.returncode;
if archivieReturnCode != 0 :
else :
cleanProject();
def cleanProject():
archiviCmd ="xcodebuild clean -project /Users/chentao/Desktop/safeBoxApp/DamoApp/DamoApp.xcodeproj -configuration ${CONFIGURATION} -alltargets";
process = subprocess.Popen(archiviCmd,shell = True);
process.wait()
archivieReturnCode = process.returncode;
if archivieReturnCode != 0 :
else :
buildWordSapce();
def buildWordSapce():
archiviCmd = "xcodebuild archive -project /Users/chentao/Desktop/safeBoxApp/DamoApp/DamoApp.xcodeproj -scheme DamoApp -archivePath /Users/chentao/Desktop/safeBoxApp/DamoApp/bin/DamoApp.xcarchive"
process = subprocess.Popen(archiviCmd,shell = True);
process.wait()
archivieReturnCode = process.returncode;
if archivieReturnCode != 0 :
else :
exportIpa();
def exportIpa():
archiviCmd ="xcodebuild -exportArchive -archivePath /Users/chentao/Desktop/safeBoxApp/DamoApp/bin/DamoApp.xcarchive -exportPath /Users/chentao/Desktop/safeBoxApp/DamoApp/DamoAppIpa -exportOptionsPlist /Users/chentao/Desktop/safeBoxApp/DamoApp/ExportOptions_appstore.plist";
process = subprocess.Popen(archiviCmd,shell = True);
process.wait()
archivieReturnCode = process.returncode;
if archivieReturnCode != 0 :
else :
cleanArchiveFile()
cleanArchiveBin()
def cleanArchiveFile():
archiviCmd ="rm -r -f /Users/chentao/Desktop/safeBoxApp/DamoApp/build";
process = subprocess.Popen(archiviCmd,shell = True);
process.wait()
archivieReturnCode = process.returncode;
if archivieReturnCode != 0 :
print ("555555")
else :
print ("00000")
def cleanArchiveBin():
archiviCmd ="rm -r -f /Users/chentao/Desktop/safeBoxApp/DamoApp/bin";
process = subprocess.Popen(archiviCmd,shell = True);
process.wait()
archivieReturnCode = process.returncode;
if archivieReturnCode != 0 :
else :
def main():
arriveProject()
if __name__ == '__main__':
main()
最后,因为有些项目使用了cocapods,在这里面打包命令有些修改,如下:
cd /Users/chentao/Desktop/ehDEMO/DamoApp
rm -r -f build/
xcodebuild -workspace DamoApp.xcworkspace -scheme DamoApp -archivePath build/DamoApp.xcarchive archive
xcodebuild -exportArchive -archivePath build/DamoApp.xcarchive -exportPath build -exportOptionsPlist ExportOptions_enterprise.plist