How to remove specific permission when build Android app with gradle?

JavaAndroidGradlePermissions

Java Problem Overview


Recently Google auto merge permission from Google Service to final release apk. Some one ask here https://stackoverflow.com/questions/30658439/why-are-permissions-being-automatically-added-to-my-androidmanifest-when-includi

My problem is some permission don't need and I don't want some sensitive permission in my app. So how to remove permission like android.permission.ACCESS_COARSE_LOCATION ? With gradle build, I don't want to disable Manifest Merger. I read some where that can config Merger to remove permission from external lib, but I can't find how to do it.

Java Solutions


Solution 1 - Java

Add attribute tools:node with a value of remove to your manifest:

<manifest ... xmlns:tools="http://schemas.android.com/tools">
    ...
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" tools:node="remove" />
    ...
</manifest>

See https://developer.android.com/studio/build/manage-manifests#node_markers

Don't forget to add the tools namespace to the root element of your manifest.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDzungPVView Question on Stackoverflow
Solution 1 - JavaJohan StuytsView Answer on Stackoverflow