I am trying to add a apikey.properties file with some client id and secrets in order to fetch a token.
Problem I run into after tring 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 appreciated !
CodePudding user response:
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