Android build.gradle buildConfigField 配置数组

我们可以在build.gradle中通过buildConfigField配置一些java的基本类型,比如Integer,boolean,还有String等,其实还可以配置数组

配置

buildConfigField可以在defaultConfig中配置,也可以在buildTypes中分别为不同的编译类型配置不同的值

android {
    defaultConfig {       
        buildConfigField "String[]", "YEYUAN_FAMILY",
                "{" +
                "\"野猿新一\"," +
                "\"野猿新二\"" +
                "}"
    }
    buildTypes {
        debug {
            buildConfigField "String[]", "YEYUAN_FAMILY",
                    "{" +
                    "\"野猿新三\"," +
                    "\"野猿新四\"" +
                    "}"
        }
        release {
            buildConfigField "String[]", "YEYUAN_FAMILY",
                    "{" +
                    "\"野猿新五\"," +
                    "\"野猿新六\"" +
                    "}"
        }
    }
}

使用

String[] family = BuildConfig.YEYUAN_FAMILY;

 

你可能感兴趣的:(android)