Android Studio two flavors with different manifest files

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"/>

Your problem is coming from a library, not your flavors. Specifically, qwknoteGIT:licencing-library is requesting CHECK_LICENSE.

If you are not using that library in all flavors, use a flavored compile statement (e.g., proCompile) to only use that library in that flavor.

If you are using the library for all flavors, but feel confident that you do not need the permission in one flavor, that’s where a tools:node attribute can be used, in the flavor’s manifest, to block out that permission supplied by the library.

And the manifest merger report is your friend. 🙂

This should solve the problem, at least. I find it useful in specifying the exact manifest to use for each variant. Cheers! It explicitly directs to the manifest file under each variant folder.

    android {
      productFlavors {
        prod {
          manifest.srcFile "prod/AndroidManifest.xml"
        }
        dev {
          manifest.srcFile "dev/AndroidManifest.xml"
        }
      }
      ...

}

Leave a Comment