【问题标题】:Build.gradle returns null properties fileBuild.gradle 返回空属性文件
【发布时间】:2014-12-13 08:46:11
【问题描述】:

我仍然真的被这个问题困住了。我试过文件,把它放在多个地方,每次都重建一个项目。同样的问题。 在 Gradle Sync 消息中,我在 build.gradle 中遇到错误:

Error:(33) A problem occurred evaluating project ':RomainGuyMuzei'.

assert localProps['keystore.props.file']
| |
| null
[sdk.dir:C:\Program Files (x86)\Android\android-studio\sdk]

有没有人能快速解决这个问题?

我将创建的 keystore.properties 文件放在哪里? 我的 gradle 文件有问题吗?它不会读吗?

def Properties localProps = new Properties()
        localProps.load(new FileInputStream(file('../local.properties')))
        def Properties keyProps = new Properties()
        assert localProps['keystore.props.file'];   //ERROR OCCURS ON THIS LINE
        keyProps.load(new FileInputStream(file(localProps['keystore.props.file'])))
        storeFile file(keyProps["store"])
        keyAlias keyProps["alias"]
        storePassword keyProps["storePass"]
        keyPassword keyProps["pass"]

我在上面指出的那条线上遇到了问题。我是否正确加载文件?显然不是。还有暗示你愿意分享吗? :]

谢谢大家。我在这个问题中包含了一堆问题/我的想法。

【问题讨论】:

标签: android import compilation gradle build.gradle


【解决方案1】:

试试这个代码:

// Create a properties object
def localProps = new Properties()

def file = "${rootDir}/local.properties"
println("Reading properties from #{file.getAbsolutePath()}. Exists? #{file.exists()}")

// Load them from a file
file.withInputStream { localProps.load(it) }

这给你三个好处:

  1. 您可以查看local.properties文件的完整路径并检查该文件是否存在。
  2. 您可以设置相对于根项目目录的路径(使用rootDir/<something>)。
  3. 尽快关闭所有输入流(通过.withInputStream 闭包)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多