android { ... def that = file('version.properties') Properties prop = new Properties() prop.load(new FileInputStream(that)) if (that.canRead()) { prop.load(new FileInputStream(that)) } def code = (prop.getProperty('VERSION_CODE') ?: "0").toInteger() + 1 if (!that.exists()) { that.createNewFile() if (that.canWrite()) prop.store(that.newWriter(), null) } ... }