我在我的应用程序的build.gradle中使用了下面的代码来加载我的签名属性来对我的应用程序进行签名。我的signing.properties在项目根文件夹中(而不是应用程序)
升级到最新的Gradle/Android插件,它现在报告signing.properties未找到,我必须将我的签名属性移动到模块根文件夹。
如何像以前一样从项目根打开文件?我在手机和穿戴应用程序之间共享我的signing.properties。
...
def Properties props = new Properties()
def propFile = new File('signing.properties')
if (propFile.canRead()) {
props.load(new FileInputStream(propFile))
if (props.containsKey('STORE_FILE') && props.containsKey('STORE_PASSWORD') &&
props.containsKey('KEY_ALIAS') && props.containsKey('KEY_PASSWORD')) {
android.signingConfigs.release.storeFile = file(props['STORE_FILE'])
android.signingConfigs.release.storePassword = props['STORE_PASSWORD']
android.signingConfigs.release.keyAlias = props['KEY_ALIAS']
android.signingConfigs.release.keyPassword = props['KEY_PASSWORD']
} else {
println 'signing.properties found but some entries are missing'
android.buildTypes.release.signingConfig = null
}
} else {
println 'signing.properties not found'
android.buildTypes.release.signingConfig = null
}
...发布于 2018-06-01 15:14:45
应该将路径插入到子项目中。我还没有对以下内容进行测试,但希望它能给您提供基本的想法。
在根项目的build.gradle文件中添加:
subprojects {
ext.signingPropsFile = rootProject.file('signing.properties')
}然后,每当一个子项目需要读取该文件时,它可以在其构建脚本中使用以下内容:
if (signingPropsFile.canRead()) {
def props = new Properties()
props.load(signingPropsFile.newReader('UTF-8'))
...
}我强烈建议您在加载文本文件时指定字符集。如果您的属性文件不使用UTF-8,那么将上面的"UTF-8“更改为”ISO8859_1“(这是您的示例假设的字符编码)。
Note您实际上可以在您的子项目中直接使用rootProject.file(),但是如果您移动该文件,那么您还必须更新您的所有子项目的构建文件。因此,配置注入是一种更好的方法。
https://stackoverflow.com/questions/50642196
复制相似问题