doorbell icon indicating copy to clipboard operation
doorbell copied to clipboard

Read from environment variable for CLOUD_VISION_API_KEY

Open arvindpdmn opened this issue 8 years ago • 1 comments

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.

arvindpdmn avatar Jan 11 '18 08:01 arvindpdmn

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);

jdkoren avatar Jan 11 '18 15:01 jdkoren