Gradle manifest merge tool Placeholder support

Yup it’s been a while, but hey! it’s new year resolutions time, am i right?

Ok so, today I’d like to share some coolness about the manifest merger tool . It let’s you do some interesting things, among them Placeholder support.

What does this mean exactly?

Simply put, it lets you tokenize values within your manifest file to have them be filled in with values from different build/flavor variants. pretty cool.

Allow me to illustrate with a quick example

<provider
     android:name="com.qtcstation.MyProvider"
     android:authorities="@string/provider_authority"
     android:exported="false">
</provider>

This is fine right? You can define a string resource for each variant where you would need a different Content provider authority.

But wait! this could be cleaner thanks to Placeholder support from the manifest merge tool.

Check this out:

<provider
     android:name="com.qtcstation.MyProvider"
     android:authorities="${applicationId}.MyProvider"
     android:exported="false">
        </provider>

This is cool! So now your content provider can be defined by the application id defined by your build type or build flavor.
The Gradle plugin will implicitly provide a resolution for ${applicationId} but what’s even more cool is that you can define your own custom placeholders. Freakin cool!

android {
    defaultConfig {
        manifestPlaceholders = [ activityLabel:"defaultName"]
    }
    productFlavors {
        free {
        }
        pro {
            manifestPlaceholders = [ activityLabel:"proName" ]
        }
    }

Take a look at the full documentation here http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger

Leave a Reply

Your email address will not be published. Required fields are marked *