Skip to content

Instantly share code, notes, and snippets.

@tiiime
Created January 8, 2024 05:48
Show Gist options
  • Save tiiime/3a0e0bf6b6a9bf1874a861f77c435b91 to your computer and use it in GitHub Desktop.
Save tiiime/3a0e0bf6b6a9bf1874a861f77c435b91 to your computer and use it in GitHub Desktop.
gradle task 输出 aar 依赖到 mrDebugDependencies.txt 文件,使用 parse_aar_activity.py 读取 mrDebugDependencies.txt,输出所有 activity 以及所在的 aar 文件。
// 放到 app/build.gradle 文件内
task showDeps {
doLast {
project.configurations.mrDebugRuntimeClasspath.each { File file ->
project.file('mrDebugDependencies.txt') << "${file.path} \n"
}
}
}
import zipfile
import xml.etree.ElementTree as ET
def read_aar(aar_file):
# 指定aar文件的路径
# 打开aar文件
aar_zip = zipfile.ZipFile(aar_file)
# 获取AndroidManifest.xml文件
manifest_xml = aar_zip.read('AndroidManifest.xml')
# 解析成XML树
root = ET.fromstring(manifest_xml)
# 打印所有activity
for activity in root.findall('application/activity'):
print(aar_file + "/" + activity.get('{http://schemas.android.com/apk/res/android}name'))
aar_zip.close()
with open('mrDebugDependencies.txt') as f:
for line in f:
try:
read_aar(line.strip())
except:
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment