我正在使用 Android Studio 在 Ubuntu 14.04 系统上构建我的项目.
I am using Android Studio to build my project on an Ubuntu 14.04 system.
我在 build.gradle 文件中编写了以下内容,以避免在我的 git 存储库中硬编码 storeFile、storePassword、keyAlias 和 keyPassword:
I wrote the following in my build.gradle files to avoid hardcoding storeFile, storePassword, keyAlias and keyPassword in my git repo:
signingConfigs {
debug {
storeFile file(System.getenv("KEYSTORE"))
storePassword System.getenv("KEYSTORE_PASSWORD")
keyAlias System.getenv("KEY_ALIAS")
keyPassword System.getenv("KEY_PASSWORD")
}
但 gradle 同步错误并出现以下错误:Error:(49, 0) path 和 baseDir 都不能为 null 或空字符串.path='null' basedir='./pathto/TMessagesProj'
But gradle sync errors out with the following: Error:(49, 0) Neither path nor baseDir may be null or empty string. path='null' basedir='./pathto/TMessagesProj'
我的 .bashrc 包含:source ~/.gradlerc
并且我的 ~/.gradlerc 包含以下内容:
My .bashrc contains: source ~/.gradlerc
and my ~/.gradlerc contains the following:
export KEYSTORE="/home/myname/keystore/mykey"
export KEYSTORE_PASSWORD='mypass'
export KEY_ALIAS='mykey'
export KEY_PASSWORD='keypass'
我已确认 shell 正确导入了这些变量.但是我不确定为什么 Android Studio 中的构建环境没有收到它.
I've confirmed that these variables are imported correctly by the shell. However I'm unsure of why it isnt received by the build environment in Android Studio.
在 gradle 中使用环境变量的正确方法是什么?
What's the proper way to use environment variables in gradle?
我也喜欢在我的环境变量中包含我的密钥库信息,而不是在项目中包含它.您的代码看起来不错,但我在文件路径上遇到了同样的问题.我通过在将它传递给 file()
之前将该值转换为字符串来解决它:
I also like having my keystore information on my environment variables, rather than having it inside the project. Your code seems fine, but I was having the same issue with the file path. I solved it by converting that value to string before passing it to file()
:
signingConfigs {
debug {
storeFile file(String.valueOf(System.getenv("KEYSTORE")))
storePassword System.getenv("KEYSTORE_PASSWORD")
keyAlias System.getenv("KEY_ALIAS")
keyPassword System.getenv("KEY_PASSWORD")
}
这篇关于使用Android Studio在gradle中使用系统环境变量的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!