在gradle.properties里面定义变量
APP_NAME="HelloWorld"
DB_VERSION=101
在build.gradle里面引用变量
buildTypes {
release {
buildConfigField "String", "APP_NAME", "${APP_NAME}"
buildConfigField "Integer", "DB_VERSION", "${DB_VERSION}"
}
debug {
buildConfigField "String", "APP_NAME", "${APP_NAME}"
buildConfigField "Integer", "DB_VERSION", "${DB_VERSION}"
}
}
gradle.properties里面定义的变量是存放在project对象中的,还可以通过另一种方法调用
appName = appName
defaultConfig {
manifestPlaceholders = [
appName : project.property("appName").toString(),
dbVersion: 101
]
}