如何为 build.gradle 增值?
how to add value to build.gradle?
有没有办法处理共享偏好?
或者,
将数据库列值添加到 build.gradle?
buildConfigField "String", "secretKey", "\"here should be the value i want\""
在根目录下创建一个文件,例如:apikey.properties
SECRET_KEY=YOUR_SECRET_KEY
在你build.gradle阅读apikey.properties
def apikeyPropertiesFile = rootProject.file("apikey.properties")
def apikeyProperties = new Properties()
apikeyProperties.load(new FileInputStream(apikeyPropertiesFile))
android {
defaultConfig {
buildConfigField("String", "SECRET_KEY", apikeyProperties['SECRET_KEY'])
}
}
您可以使用 BuildConfig
对象访问您的字段。
String secretKey = BuildConfig.SECRET_KEY;
有没有办法处理共享偏好? 或者,
将数据库列值添加到 build.gradle?
buildConfigField "String", "secretKey", "\"here should be the value i want\""
在根目录下创建一个文件,例如:apikey.properties
SECRET_KEY=YOUR_SECRET_KEY
在你build.gradle阅读apikey.properties
def apikeyPropertiesFile = rootProject.file("apikey.properties")
def apikeyProperties = new Properties()
apikeyProperties.load(new FileInputStream(apikeyPropertiesFile))
android {
defaultConfig {
buildConfigField("String", "SECRET_KEY", apikeyProperties['SECRET_KEY'])
}
}
您可以使用 BuildConfig
对象访问您的字段。
String secretKey = BuildConfig.SECRET_KEY;