Set a global variable in gradle that can use in manifest file

前端 未结 4 1514
旧时难觅i
旧时难觅i 2020-12-14 03:41

I want to create a global variable similar with applicationId. It is set value in build.gradle and will be used in manifest. Is it possible?

4条回答
  •  执念已碎
    2020-12-14 04:10

    While Marko's answer seems to work, there's currently a better solution that doesn't require adding variables to the string resource files.

    The manifest merger accepts placeholders:

    For custom placeholders replacements, use the following DSL to configure the placeholders values :

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

    will substitute the placeholder in the following declaration :

    
    

    You can also manipulate those strings with groovy functions.

提交回复
热议问题