Where to set GOOGLE_APPLICATION_CREDENTIALS variable in android project?
Asked Answered
M

1

6

I am developing an android application which requires use of google vision service provided by Google Cloud Platform. For authentication, this uses a class GoogleCredential class, the code for which can be found here:

https://cloud.google.com/vision/docs/label-tutorial#authenticating

I need to set GOOGLE_APPLICATION_CREDENTIALS variable as an environment variable pointing to a json file downloaded from another link, which is not important.

The question is: When I set the environment variable using

Uri otherPath = Uri.parse("android.resource://com.example.himanshu.myapplication/DtnPhotoShare-ff552ae2c96c.json");
    System.setProperty("**GOOGLE_APPLICATION_CREDENTIALS**",otherPath.toString());

It gives me exception :

java.io.IOException: The Application Default Credentials are not available. They are available if running on Google App Engine, Google Compute Engine, or Google Cloud Shell. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials.

in line

GoogleCredential credential =
                GoogleCredential.getApplicationDefault().createScoped(VisionScopes.all());

All the code can be found in the link given above.

Marchesa answered 24/10, 2016 at 18:32 Comment(1)
have u got solution for thisCyte
T
-1

You need service key on your disk and on linux based machine you can

export GOOGLE_APPLICATION_CREDENTIALS=<path_to_service_credential_file>

Or alternatively add this to ~/.bashrc (located in your home directory) file and source it so that this environment variable can be accessed by the library.

Tower answered 4/1, 2017 at 13:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.