第三方库比较多的场景,需要查看权限是哪个aar申请的。
AndroidManifest.xml 中内容的来源:
项目自身 AndroidManifest.xml
子 module 中的 AndroidManifest.xml
依赖中的 AndroidManifest.xml
gradle 中的代码修改
修改gradle脚本
afterEvaluate {
tasks.matching {
(it.name == "processDebugManifest")
}.each { task ->
String permission = "android.permission.REQUEST_INSTALL_PACKAGES"
task.getInputs().files.files.each {
// println("permission:${it.name} ${it.absolutePath}");
if (findPermission(it, permission)) {
println("manifest file:$it has permission $permission")
}
}
}
}
def findPermission(File xmlFile, String permission) {
if(!xmlFile.name.endsWith("xml"))
return false;
def androidManifest = new XmlParser().parse(xmlFile)
def hasPermission = false
androidManifest["uses-permission"].each {
it.attributes().each { attrItem ->
// println("attributeName:[" + attrItem.key + "], value:[" + attrItem.value +"]");
def permissionName = attrItem.value;
if (permissionName == permission) {
hasPermission = true
}
}
}
return hasPermission
}
输出打印结果
manifest file:/xxx/AndroidManifest.xml has permission android.permission.REQUEST_INSTALL_PACKAGES