简体   繁体   中英

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:

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? Is there something wrong with my gradle file? 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.
  2. You can set paths relative to the root project dir (using rootDir/<something> ).
  3. All input streams are closed as soon as possible (via the .withInputStream closure).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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