在java代码Activity或者Fragment中如何如何调用build.gradle的变量:废话不多说直接上代码:
build.gradle代码片段
apply plugin: 'com.android.application'
android {
...
buildTypes {
debug {
signingConfig signingConfigs.debug
# boolean类型数据
buildConfigField "boolean", "SHOW_LOGS", "Boolean.parseBoolean(\"true\")"
# String类型数据
buildConfigField "String", "HOST", "\"www.xuegou121.com\""
}
release {
signingConfig signingConfigs.releaseKeystore
buildConfigField "boolean", "SHOW_LOGS", "Boolean.parseBoolean(\"false\")"
buildConfigField "String", "HOST", "\"www.xuegou121.com""
}
}
...
}
将build.gradle SYNC以后就可以在 Activity中使用,示例:
boolean isShowLog = BuildConfig.SHOW_LOGS;
String host = BuildConfig.HOST;