13

I'm setting up an Android gradle project with a few product flavors. I would like to have the <uses-permission android:name="android.permission.INTERNET" /> permission in all but one of my flavors. I know it is possible to have a particular flavor add a permission, but is it possible to have a flavor remove one?

The only other solution to this that I can think of is adding the <uses-permission android:name="android.permission.INTERNET" /> permission to all of my flavors except that one, which seems quite painful.

Matthew
  • 6,356
  • 9
  • 47
  • 59

3 Answers3

22

I know this is old but now there is a new attribute called tools:node="remove" that enables you to remove a tag from the Manifest.

Declare the header of your manifest as follows:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">

Also you have to add your tag like this:

<uses-permission android:name="android.permission.INTERNET" tools:node="remove" />

I hope this helps others.

Source: HERE

Also Android documentation: HERE

EDIT:

Edited the answer to match new API changes. Thanks to Martin L. for his comment

Cata
  • 11,133
  • 11
  • 65
  • 86
  • 1
    That's part of the answer - but how do you limit the "remove" directive to a particular flavor or build type? The OP wants the permission to appear in all but 1 flavor, and they're trying to avoid duplicate manifest files. I see in the Manifest Merger documentation that there's a tools:selector attribute, but it only shows examples related to package names. http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger – Devon Biere Jul 17 '15 at 14:27
  • 1
    It's "tools:node=remove", not "tools:merge": – Martin L. Mar 06 '17 at 19:51
14

According to docs you can:

  1. remove permission with adding to your manifest something like this <permission android:name="permissionOne" tools:node="remove"/>

  2. and declare separate AndroidManifest.xml parts for each flavor in src/myFlavor/AndroidManifest.xml which will be merged this main AndroidManifest.xml

FeelGood
  • 5,594
  • 2
  • 25
  • 22
1

gradle merges manifests so probably not. I have solved similar problem (broadcast receivers package names) by removing tag from main manifest and adding it to all specific flavors.

robotoaster
  • 3,082
  • 1
  • 24
  • 23