Matthew
Matthew

Reputation: 6496

Removing AndroidManifest element with gradle product flavors

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.

Upvotes: 13

Views: 9903

Answers (3)

Cata
Cata

Reputation: 11211

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

Upvotes: 22

FeelGood
FeelGood

Reputation: 5614

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

Upvotes: 15

robotoaster
robotoaster

Reputation: 3122

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.

Upvotes: 1

Related Questions