Pankaj Pankaj - 1 month ago 36
Android Question

Android Studio - Assigning multiple value to ManifestPlaceholders in Gradle

I have two environment of my project one Prod another one is Staging. So whenever I have to build any of the environment, I have to change multiple keys like map key, label name and other things in manifest. So I have searched and find out some of the solutions and manifestPlaceholders is one of them.

Now what I want to do is to assign multiple value in manifestPlaceholders. So can I put multiple values in it and yes then how to put multiple values in it. Here is the code for the manifestPlaceholders

buildTypes {
debug {
manifestPlaceholders = [ google_map_key:"your_dev_key"]
}
release {
manifestPlaceholders = [ google_map_key:"prod_key"]
}
}

Answer

I have solved my problem as below code by adding multiple manifestPlaceholders values. Added this to my module build.gradle.

productFlavors {
        staging {
            applicationId "xxxxxxxxxxx"
            manifestPlaceholders = [ google_map_key:"xxxxxxxxxx", app_label_name:"xxxxxxx"]
            buildConfigField 'String', 'BASE_URL', '"xxxxxxxxxx"'
        }
        prod {
            applicationId "xxxxxxxxxxx"
            manifestPlaceholders = [ google_map_key:"xxxxxxxxxx", app_label_name:"xxxxxxx"]
            buildConfigField 'String', 'BASE_URL', '"xxxxxxxxxx"'
        }
    }

EDIT: You can use resValue also as Emanuel Moecklin suggested in comments.

productFlavors {
            staging {
                applicationId "xxxxxxxxxxx"
                manifestPlaceholders = [ google_map_key:"xxxxxxxxxx", app_label_name:"xxxxxxx"]
                buildConfigField 'String', 'BASE_URL', '"xxxxxxxxxx"'
                resValue "string", "base_url", "xxxxxxxxxx"
            }
            prod {
                applicationId "xxxxxxxxxxx"
                manifestPlaceholders = [ google_map_key:"xxxxxxxxxx", app_label_name:"xxxxxxx"]
                buildConfigField 'String', 'BASE_URL', '"xxxxxxxxxx"'
                resValue "string", "base_url", "xxxxxxxxxx"
            }
        }