define manifest place holders in build.gradle
<p>I have a few manifest placeholders in my <code>AndroidManifest.xml</code> file</p>

<p>In <code>build.gradle</code> I want to dynamically populate those values depending on my flavor and build type.</p>

<p>How can I do that ? </p>

<p>I wrote a function that does the following </p>

<pre><code>def getKey() {
    def KeyToReturn = ""
    android.applicationVariants.all { variant -&gt;
        printout("getKey: ${variant.name}")
        def flavor = "default";
        if (variant.productFlavors.size() &gt; 0)
            flavor = variant.productFlavors.get(0);


        def buildType = variant.buildType.name

        if (buildType == "debug" || buildType == "staging") {
            if (flavor.name == "one") {
                KeyToReturn = test_key_1
            }
            if (flavor.name == "two") {
                KeyToReturn = test_key_2
            }

        }
        if (buildType == "release") {
            if (flavor.name == "one") {
                KeyToReturn = live_key_1
            }
            if (flavor.name == "two") {
                KeyToReturn = live_key_2
            }
        }
    }
    printout("KeyToReturn:" + KeyToReturn)
    return KeyToReturn
}
</code></pre>

<p>I have this in my android.defaultConfig</p>

<pre><code>defaultConfig {
    minSdkVersion 15
    targetSdkVersion 23
    versionCode getVersionCode1()
    versionName getVersionName1() + ""
    manifestPlaceholders = [key: getKey()]
}
</code></pre>

<p>This is what my AndroidManifest.xml relevant part contains</p>

<pre><code>&lt;meta-data
            android:name="key"
            android:value="${key}"/&gt;
</code></pre>

<p>The problem is when I look in the built AndroidManifest.xml file
the ${key} value is an empty string.</p>

<p>How do I populate this value correctly ?</p>