首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法再找到Gradle signing.properties

无法再找到Gradle signing.properties
EN

Stack Overflow用户
提问于 2018-06-01 11:15:14
回答 1查看 1.4K关注 0票数 0

我在我的应用程序的build.gradle中使用了下面的代码来加载我的签名属性来对我的应用程序进行签名。我的signing.properties在项目根文件夹中(而不是应用程序)

升级到最新的Gradle/Android插件,它现在报告signing.properties未找到,我必须将我的签名属性移动到模块根文件夹。

如何像以前一样从项目根打开文件?我在手机和穿戴应用程序之间共享我的signing.properties。

代码语言:javascript
复制
...
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
}
...
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-01 15:14:45

应该将路径插入到子项目中。我还没有对以下内容进行测试,但希望它能给您提供基本的想法。

在根项目的build.gradle文件中添加:

代码语言:javascript
复制
subprojects {
    ext.signingPropsFile = rootProject.file('signing.properties')
}

然后,每当一个子项目需要读取该文件时,它可以在其构建脚本中使用以下内容:

代码语言:javascript
复制
if (signingPropsFile.canRead()) {
    def props = new Properties()
    props.load(signingPropsFile.newReader('UTF-8'))
    ...
}

我强烈建议您在加载文本文件时指定字符集。如果您的属性文件不使用UTF-8,那么将上面的"UTF-8“更改为”ISO8859_1“(这是您的示例假设的字符编码)。

Note您实际上可以在您的子项目中直接使用rootProject.file(),但是如果您移动该文件,那么您还必须更新您的所有子项目的构建文件。因此,配置注入是一种更好的方法。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50642196

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档