Grandle全局变量定义及引用

时间:2021-10-25 16:05:12

在Project的build.gradle脚本中定义一些全局变量

ext {
compileSdkVersion = 21
buildToolsVersion = "24.0.1"
minSdkVersion = 9
targetSdkVersion = 19
versionCode = 29
versionName = '3.1.0'
targetCompatibility = 1.7
sourceCompatibility = 1.7
}

在Module的build.gradle脚本中调用

android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion"
buildConfigField "String", "BUILD_DATE", "\"${new Date().toLocaleString()}\"";
multiDexEnabled true
}
}