Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing AndroidManifest element with gradle product flavors

Tags:

android

gradle

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.

like image 872
Matthew Avatar asked Mar 13 '14 22:03

Matthew


People also ask

What is Gradle product flavors?

Product flavors are a powerful feature of the Gradle plugin from Android Studio to create customised versions of products. They form part of what we call Build Variants.

How do I get the current flavor in Gradle?

There is no direct way to get the current flavor; the call getGradle().

What are buildTypes and product Flavours in Gradle and what can you use them for?

Build Variants are the result of Gradle using a specific set of rules to combine settings, code, and resources configured in your build types and product flavors. Build Type applies different build and packaging settings. An example of build types are “Debug” and “Release”.

What is Buildtype in Gradle Android?

A build type determines how an app is packaged. By default, the Android plug-in for Gradle supports two different types of builds: debug and release . Both can be configured inside the buildTypes block inside of the module build file.


1 Answers

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

like image 132
FeelGood Avatar answered Sep 20 '22 15:09

FeelGood