简体   繁体   English

Build.gradle返回空属性文件

[英]Build.gradle returns null properties file

I am still really stuck on this problem. 我仍然真的陷在这个问题上。 I have tried file, and put it in multiple places and did a project rebuild each time. 我尝试过文件,并将其放在多个位置,并且每次都进行项目重建。 Same problem. 同样的问题。 In the Gradle Sync messages I am getting an error in build.gradle: 在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]

Does anyone have the quick fix for this? 有人对此有快速解决方案吗?

Where do I put the keystore.properties file that I created? 我将创建的keystore.properties文件放在哪里? Is there something wrong with my gradle file? 我的gradle文件有问题吗? That it will not read it? 那会不会读呢?

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"]

I am hitting a problem on the line I point out above. 我在上面指出的线上遇到了一个问题。 Am I loading the file correctly? 我是否正确加载文件? Obviously not. 显然不是。 Anymore hints your willing to share? 是否再暗示您愿意分享? :] :]

Thanks all. 谢谢大家 I wrapped a bunch of questions/my thoughts in this question. 我在这个问题中提出了很多问题。

Try this code: 试试这个代码:

// 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) }

This gives you three advantages: 这给您带来三个优点:

  1. You can see the full path of the local.properties file and inspect whether the file exists. 您可以查看local.properties文件的完整路径,并检查该文件是否存在。
  2. You can set paths relative to the root project dir (using rootDir/<something> ). 您可以设置相对于根项目目录的路径(使用rootDir/<something> )。
  3. All input streams are closed as soon as possible (via the .withInputStream closure). 尽快关闭所有输入流(通过.withInputStream闭包)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM