0

I am trying to add a apikey.properties file with some client id and secrets in order to fetch a token.

The problem I run into after trying the example given by Victory in this thread: Where to keep the OAuth client credentials on Android

I run into this issue when trying to build:

Build file 'C:\app root\app\build.gradle' line: 7

A problem occurred evaluating project ':app'.
> C:\app root\apikey.properties (The system cannot find the file specified)

build.gradle(:app):

...
def apikeyPropertiesFile = rootProject.file("apikey.properties")
def apikeyProperties = new Properties()
apikeyProperties.load(new FileInputStream(apikeyPropertiesFile))
...

...
 // should correspond to key/value pairs inside the file
        buildConfigField("String", "scope", apikeyProperties['scope'])
        buildConfigField("String", "client_id", apikeyProperties['client_id'])
        buildConfigField("String", "client_secret", apikeyProperties['client_secret'])
        buildConfigField("String", "grant_type", apikeyProperties['grant_type'])
...

apikey.properties file:

scope=xxx
client_id=xxx
client_secret=xxx
grant_type=xxx

Not sure what I am doing wrong here, any help is appreciated!

CompileNow
  • 79
  • 14
  • Have you placed the file in` project/apikey.properties` as directed in the example ? Relative to the `project/app/build.gradle` file. – KE Keronei Oct 21 '21 at 12:35
  • Yes, the values were highlighted in Intellij and when moving the apikey.propeties to other locations they were not found any more. So it seems like variables would somehow propagate but then the file did was not found when building... BroscR below posted a solution that works.. – CompileNow Oct 21 '21 at 12:48

1 Answers1

1

Try this.

gradle file..

    Properties properties = new Properties()
    if (rootProject.file("apikey.properties").exists()) {
        properties.load(rootProject.file("apikey.properties").newDataInputStream())
    }
    def mapsApiKey = properties.getProperty("MAPS_API_KEY")
     defaultConfig {
 buildConfigField("String", "MAPS_API_KEY", "\"$mapsApiKey\"")
}

apikey.properties..

MAPS_API_KEY=AIzqwdqwdqwdqwdqwdqdww
BroscR
  • 167
  • 2
  • 11
  • Thank you! Works properly. Do you know if I can use Replace Tokens in Azure DevOps to replace these values, by any chance? https://marketplace.visualstudio.com/items?itemName=qetza.replacetokens – CompileNow Oct 21 '21 at 12:45
  • No I don't know. I'm sorry but if you want can new question created .. – BroscR Oct 21 '21 at 12:49
  • Ok, yes will try it out and see if it works and else post a new question. Thanks again! – CompileNow Oct 21 '21 at 12:53