How to get a resource value in build.gradle?

前端 未结 3 1573
走了就别回头了
走了就别回头了 2020-12-14 07:59

The resValue method (or whatever it\'s called) allows you to set a resource value in buildTypes or productFlavors. I

3条回答
  •  抹茶落季
    2020-12-14 08:25

    If you are only trying to set the App Label (or other manifest values) you can solve this with manifest placeholders.

    android {
    
        productFlavors {
            Foo {
                 applicationId "com.myexample.foo"
                 manifestPlaceholders.appName = "Foo"
            }
    
            Bar {
                 applicationId "com.myexample.bar"
                 manifestPlaceholders.appName = "Bar"
            }
        }
    
        buildTypes {
            release {
                manifestPlaceholders.appNameSuffix =""
            }
    
            debug {
                manifestPlaceholders.appNameSuffix =".Debug"
                applicationIdSuffix ".debug"
            }
        }
    }
    

    Then in your Android Manifest you simply use both placeholders for your app name (or other values)

     
    

    This allow you to install all 4 variants side by side on a single device as well as give them different names in the app drawer / launcher.

    EDIT 11/22/2019

    Updated how placeholders values are set based on feedback from @javaxian

提交回复
热议问题