Android: Different permissions for different flavors
Asked Answered
E

2

7

I have An app with tow flavors ... only one of them needs some permissions. How can I request these permissions only for this flavor during building apk?

These are the permissions needed:

 <uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.INTERNET" />
Embolism answered 6/11, 2017 at 20:20 Comment(0)
L
16

For the purposes of this answer, I assume that you have two product flavors, chocolate and vanilla. The chocolate one is the one that needs the additional permissions.

Step #1: In src/main/AndroidManifest.xml, put the <uses-permission> elements that are in common between all the flavors

Step #2: Create src/chocolate/, a source set that will hold source that will only be used for chocolate builds, not vanilla builds

Step #3: In src/chocolate/AndroidManifest.xml, inside an otherwise-empty <manifest> element, put the <uses-permission> elements that chocolate needs that vanilla does not

Now, your chocolate builds will have all of the permissions, while vanilla builds will only have those from the main manifest.

Loreanloredana answered 6/11, 2017 at 20:22 Comment(1)
I'll try this solution.Embolism
H
1

For each flavor you have to define a manifest wich contains unsimilarities

Handclap answered 6/11, 2017 at 20:21 Comment(2)
Is this present by default or should I define them?Embolism
you should define themHandclap

© 2022 - 2024 — McMap. All rights reserved.