如何找到依赖项使用的权限? - 安卓

发布于 2025-01-30 12:42:01 字数 382 浏览 2 评论 0原文

我正在尝试将Android应用上传到Play商店,但是由于背景位置的许可,请继续被拒绝:“ 功能不符合背景位置访问的要求 ”。

我的清单声明Access_Fine_Location和Access_coarse_location,但不包括Access_Background_location。由于我的应用目标API 30和最小API为29,因此我不会隐式使用背景位置。

但是,当我将应用程序上传到Play商店时,我可以看到我的捆绑包包括android.permission.access_background_location,这使我相信我的应用程序中的某些依赖性正在使用此许可。

这可能吗?如果是这样,我怎么能找到哪个?

I'm trying to upload my Android app to the Play Store, but keep being refused because of background location permission: "Feature does not meet requirements for background location access".

My manifest declares ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION, but does not include ACCESS_BACKGROUND_LOCATION. As my app target API 30 and the minimum API is 29 I am not implicitly using background location.

Yet, when I upload my app in the Play Store I can see that my bundle includes android.permission.ACCESS_BACKGROUND_LOCATION which leaves me to believe that some dependency in my app is using this permission.

Is this possible? If so, how could I find which is?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美人迟暮 2025-02-06 12:42:01

有时,我们确实需要列出依赖关系引入的所有权限。这是我写的脚本。将此脚本添加到您的应用程序build.gradle,

import com.android.build.gradle.AppExtension
import com.android.build.gradle.internal.api.ApplicationVariantImpl
import com.android.build.gradle.internal.publishing.AndroidArtifacts

// Gradle script to list permissions of dependencies.
def androidExtension = project.extensions.findByType(AppExtension.class)
if (androidExtension != null) {
    project.afterEvaluate {
        tasks.register('listpermissions') {
            doFirst {
                androidExtension.applicationVariants.forEach {
                    def variantData = (it as ApplicationVariantImpl).variantData
                    def manifests = variantData.variantDependencies.getArtifactCollection(
                            AndroidArtifacts.ConsumedConfigType.RUNTIME_CLASSPATH,
                            AndroidArtifacts.ArtifactScope.ALL,
                            AndroidArtifacts.ArtifactType.MANIFEST)
                    println("================================================================================================")
                    println('| LIST PERMISSIONS FOR ' + it.name)
                    manifests.forEach { manifest ->
                        if (manifest.file.exists()) {
                            def xml = new XmlSlurper().parseText(manifest.file.text)
                            def usesPermissions = xml.'uses-permission'
                            if (usesPermissions.size() > 0) {
                                println("| LIBRARY: " + manifest.file.parentFile.name + ' (' + usesPermissions.size() + ')')
                                usesPermissions.each { println("| PERMISSION: " + it.'@android:name') }
                                println("================================================================================================")
                            }
                        }
                    }
                }
            }
        }
    }
}

然后通过gradlew:app:listPermissions来列出每个依赖性使用的所有权限。例如,

================================================================================================
| LIST PERMISSIONS FOR googleRelease
| LIBRARY: jetified-vmlib-3.0.3 (1)
| PERMISSION: android.permission.ACCESS_NETWORK_STATE
================================================================================================
| LIBRARY: jetified-matisse-1.3.1 (2)
| PERMISSION: android.permission.WRITE_EXTERNAL_STORAGE
| PERMISSION: android.permission.READ_EXTERNAL_STORAGE
================================================================================================
| LIBRARY: biometric-1.1.0 (2)
| PERMISSION: android.permission.USE_BIOMETRIC
| PERMISSION: android.permission.USE_FINGERPRINT
================================================================================================
| LIBRARY: jetified-vmlib-network-3.0.1 (2)
| PERMISSION: android.permission.ACCESS_NETWORK_STATE
| PERMISSION: android.permission.INTERNET
================================================================================================
....

Sometimes we do need to list all permissions introduced by our dependencies. Here is the script I wrote to do this. Add this script to your app build.gradle,

import com.android.build.gradle.AppExtension
import com.android.build.gradle.internal.api.ApplicationVariantImpl
import com.android.build.gradle.internal.publishing.AndroidArtifacts

// Gradle script to list permissions of dependencies.
def androidExtension = project.extensions.findByType(AppExtension.class)
if (androidExtension != null) {
    project.afterEvaluate {
        tasks.register('listpermissions') {
            doFirst {
                androidExtension.applicationVariants.forEach {
                    def variantData = (it as ApplicationVariantImpl).variantData
                    def manifests = variantData.variantDependencies.getArtifactCollection(
                            AndroidArtifacts.ConsumedConfigType.RUNTIME_CLASSPATH,
                            AndroidArtifacts.ArtifactScope.ALL,
                            AndroidArtifacts.ArtifactType.MANIFEST)
                    println("================================================================================================")
                    println('| LIST PERMISSIONS FOR ' + it.name)
                    manifests.forEach { manifest ->
                        if (manifest.file.exists()) {
                            def xml = new XmlSlurper().parseText(manifest.file.text)
                            def usesPermissions = xml.'uses-permission'
                            if (usesPermissions.size() > 0) {
                                println("| LIBRARY: " + manifest.file.parentFile.name + ' (' + usesPermissions.size() + ')')
                                usesPermissions.each { println("| PERMISSION: " + it.'@android:name') }
                                println("================================================================================================")
                            }
                        }
                    }
                }
            }
        }
    }
}

Then run the gradle task by gradlew :app:listpermissions to list all permission used by each dependecy. For example,

================================================================================================
| LIST PERMISSIONS FOR googleRelease
| LIBRARY: jetified-vmlib-3.0.3 (1)
| PERMISSION: android.permission.ACCESS_NETWORK_STATE
================================================================================================
| LIBRARY: jetified-matisse-1.3.1 (2)
| PERMISSION: android.permission.WRITE_EXTERNAL_STORAGE
| PERMISSION: android.permission.READ_EXTERNAL_STORAGE
================================================================================================
| LIBRARY: biometric-1.1.0 (2)
| PERMISSION: android.permission.USE_BIOMETRIC
| PERMISSION: android.permission.USE_FINGERPRINT
================================================================================================
| LIBRARY: jetified-vmlib-network-3.0.1 (2)
| PERMISSION: android.permission.ACCESS_NETWORK_STATE
| PERMISSION: android.permission.INTERNET
================================================================================================
....
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文