doorbell
doorbell copied to clipboard
Read from environment variable for CLOUD_VISION_API_KEY
CLOUD_VISION_API_KEY is coded within the file CloudVisionUtils.java. This is okay for dev I guess but I want to know how to move this value to an environment variable and read the value at runtime. Thanks. Not really an "issue". Rather, looking for guidance.
A common solution is to define it in a properties file (like gradle.properties)
cloud_vision_api_key="some_value_here"
Then in the build.gradle file, you apply it and create a BuildConfig field:
apply from: 'filename.properties' // Note: not required if using the default gradle.properties file
android {
...
defaultConfig {
...
buildConfigField("String", "CLOUD_VISION_API_KEY", "\"${cloud_vision_api_key}\"")
}
}
Finally in the Java code, you reference the value in the generated BuildConfig:
new VisionRequestInitializer(BuildConfig.CLOUD_VISION_API_KEY);