今天刚上班就被告知要移除 QUERY_ALL_PACKAGES 权限,做代码兼容,否则上不了 Google Play 了。
google不通过截图:

遇到这种情况,
1,首先检查Manifest中可使用了改权限,如果使用了,去掉就行了
2,还有可能是第三方的包里面包含这个权限,例如ShareSdk,这个时候编译项目,可在AndroidStudio中查看最后合并的Androidmanifest.xml文件,位于 /app/build/intermediates/merged_manifests/debug/AndroidManifest.xml(或者/app/build/intermediates/merged_manifests/release/AndroidManifest.xml)目录下
路径如下:

搜索QUERY_ALL_PACKAGES可以看到有这个权限

如何解决呢?
只需在项目build.gradle文件里添加如下代码,删除对应权限即可
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
def curFileName = output.outputFileName.toString()
def replacement = curFileName.substring(0, curFileName.indexOf("."))
output.outputFileName = curFileName.replace(replacement, fileName)
output.processResources.doFirst { pm->
String manifestPath = output.processResources.manifestFile;
def manifestContent = file(manifestPath).getText()
// 需要删除的权限
manifestContent = manifestContent.replace('<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"/>', '')
file(manifestPath).write(manifestContent)
}
}
}
