# Updating gradle file with versionCode and versionName

**URL:** <https://discuss.bitrise.io/t/updating-gradle-file-with-versioncode-and-versionname/3655>\
**Category:** Question & Answer\
**Tags:** android\
**Created:** [January 6, 2018, 12:28pm UTC](https://discuss.bitrise.io/t/updating-gradle-file-with-versioncode-and-versionname/3655 "2018-01-06T12:28:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![thaxsillion](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@thaxsillion](https://discuss.bitrise.io/u/thaxsillion)\
**Post date:** [January 6, 2018, 12:28pm UTC](https://discuss.bitrise.io/t/updating-gradle-file-with-versioncode-and-versionname/3655/1 "2018-01-06T12:28:27Z")

</div>

What is the best practice to update versionCode when deploying an app to the beta channel in Android?  
I wanted to offset the current versionCode by bitrise’s build number, but I haven’t found any custom step for retrieving such information from gradle file.

Is it a good idea to have a totally custom versionCode (currently my version codes are above 100000), so maybe using just bitrise’s build number will suffice?

Thanks in advance,  
Alex

---

<div class="post-metadata">

**Author:** ![koral](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/koral/32/357_2.png) [@koral](https://discuss.bitrise.io/u/koral)\
**Post date:** [January 6, 2018, 12:54pm UTC](https://discuss.bitrise.io/t/updating-gradle-file-with-versioncode-and-versionname/3655/2 "2018-01-06T12:54:47Z")

</div>

There is no need to modify Gradle files during build. You can calculate a build number inside buildscript:

```auto
android {
  defaultConfig {
    def buildNumber = System.getenv("BITRISE_BUILD_NUMBER") ?: "1"
    versionCode Integer.parseInt(buildNumber) + 100000
(...)

```

Another approach is to use current git commit timestamp or number of commits on the current branch. This is often sufficient if app built from given commit is always the same e.g. there is no dynamic dependencies, no content downloaded at the build time nor NDK (version of which can change over the time on bitrise).

---

<div class="post-metadata">

**Author:** ![ddoe](https://avatars.discourse-cdn.com/v4/letter/d/2bfe46/32.png) [@ddoe](https://discuss.bitrise.io/u/ddoe)\
**Post date:** [January 20, 2018, 8:46am UTC](https://discuss.bitrise.io/t/updating-gradle-file-with-versioncode-and-versionname/3655/3 "2018-01-20T08:46:04Z")

</div>

It would be nice to have a custom step for this so we could avoid making Bitrise-specific changes to our build. For now, though, this works well. Thanks!

---

<div class="post-metadata">

**Author:** ![viktorbenei](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/viktorbenei/32/18_2.png) [@viktorbenei](https://discuss.bitrise.io/u/viktorbenei)\
**Post date:** [January 20, 2018, 12:48pm UTC](https://discuss.bitrise.io/t/updating-gradle-file-with-versioncode-and-versionname/3655/4 "2018-01-20T12:48:17Z")

</div>

Depends on your setup, the **Change Android versionCode and versionName** step combined with the **Adjust BuildNumber** step can provide something like this, if you want to have a simple / static offset & use the Bitrise Build Number for the build number.

---

<div class="post-metadata">

**Author:** ![jason.atwood](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/jason.atwood/32/1712_2.png) [@jason.atwood](https://discuss.bitrise.io/u/jason.atwood)\
**Post date:** [March 3, 2018, 3:14am UTC](https://discuss.bitrise.io/t/updating-gradle-file-with-versioncode-and-versionname/3655/5 "2018-03-03T03:14:32Z")

</div>

What is the point of the `+ 100000`?

---

<div class="post-metadata">

**Author:** ![koral](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/koral/32/357_2.png) [@koral](https://discuss.bitrise.io/u/koral)\
**Post date:** [March 3, 2018, 12:19pm UTC](https://discuss.bitrise.io/t/updating-gradle-file-with-versioncode-and-versionname/3655/6 "2018-03-03T12:19:35Z")

</div>

Because OP already uses lower version codes:

> [@thaxsillion](#):
>
> currently my version codes are above 100000
