I have a few manifest placeholders in my AndroidManifest.xml
file
In build.gradle
I want to dynamically populate those values depending on my flavor and build type.
How can I do that ?
I wrote a function that does the following
def getKey() {
def KeyToReturn = ""
android.applicationVariants.all { variant ->
printout("getKey: ${variant.name}")
def flavor = "default";
if (variant.productFlavors.size() > 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
}
I have this in my android.defaultConfig
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode getVersionCode1()
versionName getVersionName1() + ""
manifestPlaceholders = [key: getKey()]
}
This is what my AndroidManifest.xml relevant part contains
<meta-data
android:name="key"
android:value="${key}"/>
The problem is when I look in the built AndroidManifest.xml file the ${key} value is an empty string.
How do I populate this value correctly ?