简单写了一个python脚本记录一下Mainfest中Activity的相关信息,代码如下:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import xml.etree.ElementTree as ET
import pandas as pd
preix="{http://schemas.android.com/apk/res/android}"
def parseXml(filePath):
tree=ET.parse(filePath)
# print(tree.getroot().attrib)
root=tree.getroot()
activitylist=[]
noScreenRotateList=[]
for application in root:
if(application.tag == "application"):
for element in application.findall("activity"):
name= element.get(preix+'name')
configChange=element.get(preix+"configChanges")
if(configChange == None):
noScreenRotateList.append({name:configChange})
else:
activitylist.append({name:configChange})
activitylist=activitylist+noScreenRotateList
buildTable(activitylist)
def buildTable(list):
a = []
b = []
for item in list:
for key in item:
a.append(key)
b.append(item[key])
dit = {'Activity':a, 'ConfigChangeOptions':b}
file_path = r'output.xlsx'
writer = pd.ExcelWriter(file_path)
df = pd.DataFrame(dit)
#columns参数用于指定生成的excel中列的顺序
df.to_excel(writer, columns=['Activity','ConfigChangeOptions'], index=False,encoding='utf-8',sheet_name='Sheet')
writer.save()
parseXml("AndroidManifest.xml")
最终输出结果为一个excel表格文件,里面记录了Activity的个数以及对象ConfigChanges参数的值