在Gradle中声明一个Java可使用的变量

生成Java常量

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
android {
buildTypes {
debug {
buildConfigField "int", "FOO", "42"
buildConfigField "String", "FOO_STRING", "\"foo\""
buildConfigField "boolean", "LOG", "true"
}

release {
buildConfigField "int", "FOO", "52"
buildConfigField "String", "FOO_STRING", "\"bar\""
buildConfigField "boolean", "LOG", "false"
}
}
}

你可以访问他们 BuildConfig.FOO

生成Android资源

1
2
3
4
5
6
7
8
9
10
android {
buildTypes {
debug{
resValue "string", "app_name", "My App Name Debug"
}
release {
resValue "string", "app_name", "My App Name"
}
}
}

您可以按照通常的方式访问它们。@string/app_nameR.string.app_name

乱码三千 – 点滴积累 ,欢迎来到乱码三千技术博客站

0%