应用权限数量异常问题:仅添加2个权限但谷歌显示8个权限
Hey, this is a super common issue with Android apps—those extra permissions you're seeing are almost certainly being pulled in by third-party dependencies you're using (like SDKs, open-source libraries, or even some legacy support libraries). The Android Gradle Plugin automatically merges all permission declarations from every module and dependency into your final app manifest, which is why you're seeing more permissions than you manually added.
Here's how to fix this step by step:
1. Identify Which Dependency Is Adding the Permissions
First, you need to pinpoint exactly where these extra permissions are coming from. Run this Gradle command in your project root:
- On macOS/Linux:
./gradlew app:mergeDebugAndroidManifest - On Windows:
gradlew.bat app:mergeDebugAndroidManifest
After running the command, navigate to app/build/intermediates/merged_manifest/debug/AndroidManifest.xml. Open this file, and you'll see comments above each permission that tell you which dependency it originated from (e.g., <!-- From library: com.example.some-sdk:1.2.3 -->).
2. Remove Unnecessary Permissions
Once you know which permissions your app doesn't need, you can explicitly exclude them from your main AndroidManifest.xml. First, make sure you add the tools namespace to your root manifest tag:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" package="your.app.package">
Then, for each permission you want to remove, add a declaration with tools:node="remove"—this tells the Gradle plugin to strip that permission from the final merged manifest. For example:
<!-- Remove permissions we don't require --> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" tools:node="remove" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" tools:node="remove" /> <uses-permission android:name="android.permission.WAKE_LOCK" tools:node="remove" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="remove" /> <uses-permission android:name="com.x.x.permission.YOUR_CUSTOM_PERMISSION" tools:node="remove" />
3. Verify and Test
After adding these removal rules, rebuild your app and re-run the merge manifest command to confirm the unwanted permissions are gone. Critical note: Before removing any permission, double-check that none of your dependencies rely on it to function properly—removing a required permission could break features from the library. Test your app thoroughly after making changes to ensure everything works as expected.
内容的提问来源于stack exchange,提问作者Modgo

