Android Studio two flavors with different manifest files

Marcus

I'm having issues with defining two different manifest files for my flavors in Android Studio. This is my current project structure:

Current project structure

The AndroidManifest.xml in the free flavor looks like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="se.example.package">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
</manifest>

The AndroidManifest.xml in the main flavor has no uses-permissions, but contains the rest of the manifest code that is shared between all flavors.

The AndroidManifest.xml in the pro flavor looks like this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="se.example.package">
    <uses-permission android:name="com.android.vending.CHECK_LICENSE" />
</manifest>

build.gradle defines the two flavors like

productFlavors {
    free {
        applicationId 'se.example.package.free'
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName '1.0'
    }
    pro {
        minSdkVersion 14
        applicationId 'se.example.package.pro'
        targetSdkVersion 21
        versionCode 2
        versionName '1.1'
    }
}

The result that I am expecting is that the different flavors defines different uses-permissions. This is not the case. The result is currently that the both flavors only defines the <uses-permission android:name="com.android.vending.CHECK_LICENSE" /> as defined in AndroidManifest.xml in the pro flavor.

I have tried:

  • Clean project
  • Rebuild project
  • Restart Android Studio
  • Sync gradle

But without success. How am I to fix this? Any help is appreciated.

EDIT 1

I changed the location of each flavors AndroidManifest.xml file from each of the res folders to free and pro folder. The result of this:

  1. Pro flavor shows Licence permission as expected.
  2. Free flavor shows permissions from both AndroidManifest.xml files, License and network permissions (Should be only network)

This feels like an issue of project structure. What to make of this?

EDIT 2

I pulled the merge reports as Commonsware hinted, these are the reports regarding uses-permissions

Free:

uses-permission#com.android.vending.CHECK_LICENSE
ADDED from qwknoteGIT:licencing-library:unspecified:26:5
    android:name
        ADDED from qwknoteGIT:licencing-library:unspecified:26:22

Pro:

uses-permission#com.android.vending.CHECK_LICENSE
MERGED from qwknoteGIT:licencing-library:unspecified:26:5
Budius

Tech background:

on this link it explains the techniques and parameters that can be use for manifest merging: http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger#TOC-tools:node-markers

One in specific is the tools:node that points out how certain XML nodes on the manifest should behave whilst merging.

Solution:

to achieve some permisions in one and different in other manifest, add ALL permissions you need to the main and in the flavours manifest remove the ones you don't need, like the example below:

free remove the check license

<uses-permission
   android:name="com.android.vending.CHECK_LICENSE" 
   tools:node="remove"/>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Is it possible to use multiple manifest files for different gradle builds/flavors?

From Dev

Test package for different flavors in Android Studio

From Dev

Android studio using flavors with <compatible-screens> in the manifest

From Dev

How to setup gradle in Android Studio to provide two flavors with different minimum SDK versions?

From Dev

Android gradle two different launcher activities for two different product flavors

From Dev

Android, Gradle, product flavors and the manifest

From Dev

How to create packages in Android Studio for different gradle flavors

From Dev

How to use flavors with different app names in Android studio?

From Dev

Android Studio build flavors - How to have same source files in diverse flavors

From Dev

Android Studio product flavors only recognized one out of two flavours

From Dev

Android Studio - nested flavors (Gradle)

From Dev

android gradle flavors in the last Android studio

From Dev

Android White Labeling using Android Studio Flavors

From Dev

Different files and gradle android studio

From Dev

Gradle signing flavors with different keys on Android

From Dev

Client ID for Android application with different flavors

From Dev

Android flavors with different dependencies and same class file

From Dev

Client ID for Android application with different flavors

From Dev

(Android) Runtime dependency managment with different flavors

From Dev

Android flavors with different dependencies and same class file

From Dev

Android: one activity in two of four flavors

From Dev

How to build product flavors from Android Studio?

From Dev

Android studio gradle flavors not showing in Build Variants

From Dev

Custom styles of product flavors in Android Studio?

From Dev

Custom styles of product flavors in Android Studio?

From Dev

Manifest Merge in Android Studio

From Dev

Manifest permission in Android Studio

From Dev

Android studio manifest issue

From Dev

Android Flavors

Related Related

  1. 1

    Is it possible to use multiple manifest files for different gradle builds/flavors?

  2. 2

    Test package for different flavors in Android Studio

  3. 3

    Android studio using flavors with <compatible-screens> in the manifest

  4. 4

    How to setup gradle in Android Studio to provide two flavors with different minimum SDK versions?

  5. 5

    Android gradle two different launcher activities for two different product flavors

  6. 6

    Android, Gradle, product flavors and the manifest

  7. 7

    How to create packages in Android Studio for different gradle flavors

  8. 8

    How to use flavors with different app names in Android studio?

  9. 9

    Android Studio build flavors - How to have same source files in diverse flavors

  10. 10

    Android Studio product flavors only recognized one out of two flavours

  11. 11

    Android Studio - nested flavors (Gradle)

  12. 12

    android gradle flavors in the last Android studio

  13. 13

    Android White Labeling using Android Studio Flavors

  14. 14

    Different files and gradle android studio

  15. 15

    Gradle signing flavors with different keys on Android

  16. 16

    Client ID for Android application with different flavors

  17. 17

    Android flavors with different dependencies and same class file

  18. 18

    Client ID for Android application with different flavors

  19. 19

    (Android) Runtime dependency managment with different flavors

  20. 20

    Android flavors with different dependencies and same class file

  21. 21

    Android: one activity in two of four flavors

  22. 22

    How to build product flavors from Android Studio?

  23. 23

    Android studio gradle flavors not showing in Build Variants

  24. 24

    Custom styles of product flavors in Android Studio?

  25. 25

    Custom styles of product flavors in Android Studio?

  26. 26

    Manifest Merge in Android Studio

  27. 27

    Manifest permission in Android Studio

  28. 28

    Android studio manifest issue

  29. 29

    Android Flavors

HotTag

Archive