1.场景gradle工程转安卓系统编译,如果需要提取gradle的external libraries包位于.idea/libraries的(python脚本)
2. Gradle__androidx_constraintlayout这样android自带的不需要导入的(把这个.idea里面复制到外面某个文件夹,手动剔除安卓自带的);./app/libs 下的一般不会太多,自己处理
2.有lib名和lib存放地址后,写一个脚本收集到某个目录下(大部分lib可提取,少部分的需要自己手动处理)
—————————————-xxxx.py———————————–
import xml.dom.minidom as xmldom
import os,re,shutil
#定义需要提取的gradle 工程目录下.idea/libraries,
path_libs_idea = “path_xxxx/idea/libraries”
allLibs = [] #查询到的libs
filePathList = []
destPath = ‘E:\xxx_dest_path’ #lib包想要存储到什么目录
def file_name_list(file_dir):
L=[]
for root, dirs, files in os.walk(file_dir):
for file in files:
if os.path.splitext(file)[1] == ‘.xml’:
L.append(os.path.join(root, file))
return L
def getJarPath(jarPath):
pattern = ‘jar://(.*)!/’
matchPath=re.search(pattern, jarPath, flags=0)
if matchPath:
# print(“jarPath.group() : “, matchPath.group())
# print(“jarPath.group() : “, matchPath.group(1))
return matchPath.group(1)
else:
# print(“not find path in “, jarPath)
return None
def getJarName(jarPath):
pathMath = jarPath.split(‘/’)
jarName = “”
for pa in pathMath:
jarName = pa
return jarName
#解析xml等
def getLibsLocPath(file):
jarData = {}
# 得到文件对象
dom_obj = xmldom.parse(file)
# 获得子标签
libraryTableComponet = dom_obj.getElementsByTagName(“component”)
# 获得子标签属性
libraryTableComponet[0].getElementsByTagName(“library”)[0].getAttribute(“name”)
jarTempPath = libraryTableComponet[0].getElementsByTagName(“library”)[0].getElementsByTagName(“CLASSES”)[0].getElementsByTagName(“root”)[0].getAttribute(“url”)
jarPath = getJarPath(jarTempPath)
#添加libs
allLibs.append(libraryTableComponet[0].getElementsByTagName(“library”)[0].getAttribute(“name”))
if jarPath:
jarData[‘path’] = jarPath
jarData[‘name’] = getJarName(jarPath)
jarData[‘package’] = libraryTableComponet[0].getElementsByTagName(“library”)[0].getAttribute(“name”)
filePathList.append(jarPath)
return jarData
else:
return None
if __name__ == “__main__”:
#定义容器
libPathList= []
files = file_name_list(path_libs_idea)
for file in files:
# print(file)
# 获得子标签属性
tempFile = getLibsLocPath(file)
if tempFile:
libPathList.append(tempFile)
# for kv in libPathList:
# #输出获得的 lib名和lib路径
# print(kv)
for path in filePathList:
try:
print(path)
shutil.move(path,destPath)
except:
print(“找不到文件或文件名冲突:” + path)
#查询到的libs
for lib in allLibs:
print(lib)