Android Studio - Assigning multiple ManifestPlaceholders in Gradle

I have two environments of my project: one is Prod , the other is Stage . Therefore, whenever I have to create an environment, I have to change several keys, such as a map key, label name, and other things in the manifest. So I searched and figured out some of the solutions, and manifestPlaceholders is one of them.

Now I want to assign multiple values ​​to manifestPlaceholders . Therefore, can I put several values ​​in it, and yes, then how can I put several values ​​in it. Here is the code for manifestPlaceholders

buildTypes { debug { manifestPlaceholders = [ google_map_key:"your_dev_key"] } release { manifestPlaceholders = [ google_map_key:"prod_key"] } } 
+5
source share
3 answers

I solved the problem as shown below by adding a few manifestPlaceholders . Added this to my build.gradle module.

 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 as well as Emanuel Moecklin suggested in the 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" } } 
+11
source

You can easily set / change multiple manifestPlaceholders. You can either determine all the values ​​at once, as in your answer, or one at a time.

 defaultConfig { // initialize more values manifestPlaceholders = [ google_map_key:"xxxxxxxxxx", app_label_name:"xxxxxxx"] // or this way manifestPlaceholders.google_map_key = "xxxxxxxxxx" manifestPlaceholders.app_label_name = "xxxxxxxxxx" } productFlavors { staging { } prod { // use some different value for prod manifestPlaceholders.google_map_key = "yyyyyyyyyy" } } 
+6
source

I mentioned both build types and fragrances

 buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' resValue "string", "google_maps_key", "release google map key" } debug { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' resValue "string", "google_maps_key", "debug google map key" } } productFlavors { alpha { applicationId = "com.example.alpha" resValue 'string', 'app_name', 'alphaapp' resValue "string", "maps_api_key", "XXXXXXXXXXXXXXXXXXXXX" } beta { applicationId = "com.example.beta" resValue 'string', 'app_name', 'betaapp' resValue "string", "maps_api_key", "XXXXXXXXXXXXXXXXXXXXXX" } } 
+1
source

Source: https://habr.com/ru/post/1244567/


All Articles