我想将我的 keystore 保存在项目目录之外。我不想将文件路径存储在存储库中,所以我将值委托(delegate)给 ~/.gradle/gradle.properties
中的适当 gradle 变量
我无法让 gradle 接受像这样的绝对路径:
/Users/username/.gradle/keystores/project/release.key
或者
~/.gradle/keystores/project/release.key
我试过:
storeFile 文件(RELEASE_STORE_FILE)
和
storeFile 新文件(RELEASE_STORE_FILE)
然而,它们似乎都不起作用。
如何通过 RELEASE_STORE_FILE
变量将绝对路径值传递给 keystore 文件?
android {
signingConfigs {
release {
storeFile file(RELEASE_STORE_FILE)
storePassword RELEASE_STORE_PASS
keyAlias RELEASE_ALIAS
keyPassword RELEASE_KEY_PASS
}
}
}
和 ~/.gradle/gradle.properties
文件:
RELEASE_STORE_FILE=/Users/username/.gradle/keystores/project/release.key
RELEASE_STORE_PASS=******
RELEASE_ALIAS=******
RELEASE_KEY_PASS=******
简而言之:我想传递一个绝对路径值给gradle。
最佳答案
我最终使用了来自 this 的一个有趣的解决方案网站。
想法是将变量保存在一个单独的文件夹中,该文件夹存储在远程存储库中。
在 ~/.gradle/gradle.properties
文件中放置:
Keys.repo=/Users/username/.signing
其中 Keys.repo
是远程存储库的本地路径。
稍后在 /Users/username/.signing/YourProjectName.properties
中你有:
RELEASE_STORE_FILE=/YourProjectName/release.keystore //in fact it's a relative path
RELEASE_STORE_PASS=xxxxx
RELEASE_ALIAS=xxxxx
RELEASE_KEY_PASS=xxxxx
您需要将release.keystore
文件存储在/Users/username/.signing/YourProjectName/release.keystore
路径
配置使用方式如下:
android {
signingConfigs {
debug { /* no changes - usual config style */ }
release {
if (project.hasProperty("Keys.repo")) {
def projectPropsFile = file(project.property("Keys.repo") + "/YourProjectName.properties")
if (projectPropsFile.exists()) {
Properties props = new Properties()
props.load(new FileInputStream(projectPropsFile))
storeFile file(file(project.property("Keys.repo") + props['RELEASE_STORE_FILE']))
storePassword props['RELEASE_STORE_PASS']
keyAlias props['RELEASE_ALIAS']
keyPassword props['RELEASE_KEY_PASS']
}
} else {
println "======================================================="
println "[ERROR] - Please configure release-compilation environment - e.g. in ~/.signing directory"
println "======================================================="
}
}
}
}
关于android - gradle 为 keystore 文件设置绝对路径值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35983677/