简体   繁体   English

使用环境变量时Android Gradle错误

[英]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.

相关问题 在 Android Studio 中为 Gradle 构建使用环境变量 - Using environment variables for Gradle builds in Android Studio 使用 Android Studio 在 gradle 中使用系统环境变量的正确方法 - Proper way to use System environment variables in gradle using Android Studio 使用Appium库在android studio中构建gradle文件时出错 - Error while builiding the gradle files in android studio using Appium libraries 错误:在Android Gradle文件中一起使用Firebase和Google Map时 - Error: while Using Firebase and Google Map together in android Gradle File 使用Android Studio 1.3.2时发生Gradle构建错误 - Gradle build error while using Android Studio 1.3.2 使用 androiddeployqt 为 android 构建 Qt 应用程序时出现 Gradle 构建错误 - Gradle build error while building Qt app for android using androiddeployqt 通过命令行使用 gradle 构建 android 应用程序时出错 - Error while building android application using gradle via command line 从Android Studio gradle build访问环境变量 - Access to environment variables from Android Studio gradle build 如何在使用“classpath”com.android.tools.build:gradle:2.3.3'时修复build.gradle错误 - How to fix build.gradle error while using “ classpath 'com.android.tools.build:gradle:2.3.3' ” 使用环境变量时如何在 ktor 中进行测试? - How to test in ktor while using environment variables?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM