BitCode脚本

在包体积优化中,需要统计不支持BitCode pod库有哪些,在pod库数量较多的情况下,使用脚本节省统计时间。

1
2
#使用检查的命令
otool -l QiBitcode/QiBitcode.framework/QiBitcode | grep __LLVM
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
#coding:utf-8
import glob, os
import subprocess
import commands
# os.chdir("/Users/jinying.zhou.o/Desktop/BaoTiJi")

fileList = [] ## 存放.a文件的数组
architectures = ['armv7','arm64','i386','x86_64']
# architectures = ['armv7','arm64']
unsupports = []
rootPath = '/Users/jinying.zhou.o/Desktop/testbitcode'

def checkBitCode(thinStr,unzipStr):
os.system(thinStr)

# 执行解压操作
os.chdir(rootPath)
# 新建文件夹
folder = endingFile
#获取此py文件路径,在此路径选创建在new_folder文件夹中的test文件夹
if not os.path.exists(folder):
os.makedirs(folder)
os.chdir(folder)
os.system(unzipStr)
# 在当前文件夹下遍历解压获得的.o
# for tempFile in glob.glob("*.txt"):

for tempFile in os.listdir(folder):
if tempFile.endswith(".o"):
checkStr = 'otool -l ' + tempFile + ' | grep bitcode'
output = commands.getstatusoutput(checkStr)
keyword = 'bitcode'
# print output
if keyword not in output[1]:
if folder not in unsupports:
print checkStr
unsupports.append(folder)
break

for root, dirs, files in os.walk(rootPath):
for file in files:
if file.endswith(".a"):
fileList.append(os.path.join(root, file))

for file in fileList:
print fileList
endingFile = file.rstrip('.a')
# 获取架构路径
for architecture in architectures:
thinStr = 'lipo -thin ' + architecture + ' ' + file + ' -output ' + endingFile + '-' + architecture + '.a'
unzipStr = 'ar -x ' + endingFile + '-' + architecture + '.a'
checkBitCode(thinStr,unzipStr)
# print(unzipStr)

print('====================')
print(unsupports)

通过此脚本排查出不支持BitCode的.a 及 Framework,不过还是要以项目中实际Build的为准

参考链接:

iOS 了解Xcode Bitcode