Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read from environment variable for CLOUD_VISION_API_KEY #16

Open
arvindpdmn opened this issue Jan 11, 2018 · 1 comment
Open

Read from environment variable for CLOUD_VISION_API_KEY #16

arvindpdmn opened this issue Jan 11, 2018 · 1 comment

Comments

@arvindpdmn
Copy link

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.

@jdkoren
Copy link
Member

jdkoren commented Jan 11, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants