在Gradle中声明一个Java可使用的变量 发表于 2020-05-18 | 生成Java常量123456789101112131415android { 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资源12345678910android { buildTypes { debug{ resValue "string", "app_name", "My App Name Debug" } release { resValue "string", "app_name", "My App Name" } }} 您可以按照通常的方式访问它们。@string/app_name或R.string.app_name 乱码三千 – 点滴积累 ,欢迎来到乱码三千技术博客站