user264953
user264953

Reputation: 1967

Android Gradle error while using environment variables

I am using the below code in my gradle file to fetch a username and password which I have added in the environment variables of my computer.

def uname = System.getenv("USERNAME")
def pwd = System.getenv("PASSWORD")
buildConfigField "String", "USERNAME", uname
buildConfigField "String", "PASSWORD", pwd

It gives me the error shown in screenshot while I try to run the app. This is a screenshot from BuildConfig.java auto generated file. It shows, the username and password is being picked up correctly by gradle, but a syntax error while using it? I am posting the error message screenshot. Is there a problem defining and using variable this way in gradle? Any help to resolve this is much appreciated

enter image description here

Upvotes: 0

Views: 815

Answers (1)

chessdork
chessdork

Reputation: 2019

The BuildConfig file is missing quotes around those strings. Try this in your build.gradle instead:

buildConfigField "String", "USERNAME", '"' + uname + '"'
buildConfigField "String", "PASSWORD", '"' + pwd + '"'

Upvotes: 2

Related Questions