[英]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. 我在gradle文件中使用以下代码来获取用户名和密码,这些用户名和密码已添加到计算机的环境变量中。
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. 这是BuildConfig.java自动生成的文件的屏幕截图。 It shows, the username and password is being picked up correctly by gradle, but a syntax error while using it? 它显示,用户名和密码已由gradle正确获取,但使用时出现语法错误? I am posting the error message screenshot. 我正在发布错误消息的屏幕截图。 Is there a problem defining and using variable this way in gradle? 在gradle中以这种方式定义和使用变量是否存在问题? Any help to resolve this is much appreciated 任何解决此问题的帮助都非常感谢
The BuildConfig file is missing quotes around those strings. BuildConfig文件缺少这些字符串周围的引号。 Try this in your build.gradle
instead: 在您的build.gradle
尝试以下build.gradle
:
buildConfigField "String", "USERNAME", '"' + uname + '"'
buildConfigField "String", "PASSWORD", '"' + pwd + '"'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.