我在应用程序的build.gradle中使用以下代码加载我的签名属性以签署我的应用程序。我的signing.properties位于项目根文件夹(不是app)
升级到最新的Gradle / Android Gradle插件,它现在报告找不到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
}
...
答案 0 :(得分:1)
new File('signing.properties')
搜索文件' signing.properties'相对于它声明的gradle文件的位置。在你的情况下,gradle文件是app / build.gradle'。
因此,请提供一条“签名”属性的路径'文件相对于' app / build.gradle'的位置文件。
答案 1 :(得分:1)
您应该将路径注入子项目。我还没有测试过以下内容,但希望能给你一个基本的想法。
在根项目的 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" (这是您的示例假设的字符编码)。
注意您实际上可以直接在子项目中使用rootProject.file()
,但如果您移动文件,则必须更新所有子项目'也建立文件。因此配置注入是一种更好的方法。