title: How can I create a default properties file if it doesn't exist in Android Gradle Build
body: <p>Currently, my android project loads two parameters from a local <a href="https://developer.android.com/reference/java/util/Properties" rel="nofollow noreferrer">properties</a> files to populate some <code>Build.Config</code> constants. The purpose of having the separate <code>local.properties</code> file is to keep it out of source control. (this file is ignored by git). The values in it are of no value to production builds and may be frequently changed by a developer. I don't want a change of these values to constitute a change in <code>build.gradle</code>. I also never want it to change just because a developer checks out a different git branch.</p>
  <p>My problem is that since this property file is not in source control, a fresh clone and checkout will fail to build because the file does not exist. In the case where the file does not exist, I want the script to create it and save default parameters to it.</p>
  <blockquote>
  <p>ERROR: C:\Users\Me\AndroidStudioProjects\MyAwesomeApp\app\local.properties (The system cannot find the file specified)</p>
  </blockquote>
  <p>My current <code>build.gradle</code> which reads from a properties file:</p>
  <pre><code>Properties properties = new Properties()
  properties.load(project.file('local.properties').newDataInputStream())
  def spoofVin = properties.getProperty('spoof.vin', '12345678901234567')
  def spoofId = properties.getProperty('spoof.id', '999999999999')
  buildConfigField(&quot;String&quot;, &quot;SPOOF_VIN&quot;, '&quot;' + spoofVin + '&quot;')
  buildConfigField(&quot;String&quot;, &quot;SPOOF_ID&quot;, '&quot;' + spoofId + '&quot;')
  </code></pre>
  <p>Example <code>app/local.properties</code> file:</p>
  <pre><code>#Change these variables to spoof different IDs and VINs. Don't commit this file to source control.
  #Wed Nov 18 12:13:30 CST 2020
  spoof.id=999999999999
  spoof.vin=12345678901234567
  </code></pre>
  <p>I'm posting my own solution below, to hopefully help someone else out if they have the same needs. I'm not a Gradle pro, so if you know an even better way to do this, post your solution.</p>