問題描述
我正在使用 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模板網!