title: Android + Gradle: Best place to set dynamic archivesBaseName
body: <p>In our Android project we want the filename of our APK to contain information such as the date, git branch name and short commit hash.</p>
  
  <p>We've been setting this as part of our <code>defaultConfig</code></p>
  
  <pre><code>android {
     defaultConfig {
        setProperty("archivesBaseName", "$projectName.$branchName.$date.$buildNumber.$versionCode-$versionName-$versionSha")    
     }
  }
  </code></pre>
  
  <p>This works most of the time but our build sometimes fails with errors pointing to the value being stale (for example after switching branches). Forcing Gradle Sync in Android Studio usually fixes it.</p>
  
  <p>So is there a better, more robust way of making sure that property stays up to date and forces a gradle sync, if necessary?</p>