How to update version number of react native app
For those wanting to automate this, and have iOS at the same time, you can use react-native-version to set the version numbers.
All you need to do is update your version number inside the package.json file and run the following:
$ npx react-native-version --never-amend
[RNV] Versioning Android...
[RNV] Android updated
[RNV] Versioning iOS...
[RNV] iOS updated
[RNV] Done
✨ Done in 0.39s.
I hope this can help others.
@Joseph Roque is correct, you need to update the version numbers in android/app/build.gradle
.
Here's how I automate this and tie it into the package's version in package.json
and git commits.
In android/app/build.gradle
:
/* Near the top */
import groovy.json.JsonSlurper
def getNpmVersion() {
def inputFile = new File("../package.json")
def packageJson = new JsonSlurper().parseText(inputFile.text)
return packageJson["version"]
}
/* calculated from git commits to give sequential integers */
def getGitVersion() {
def process = "git rev-list master --first-parent --count".execute()
return process.text.toInteger()
}
......
def userVer = getNpmVersion()
def googleVer = getGitVersion()
android {
...
defaultConfig {
.....
versionCode googleVer
versionName userVer
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
Notes:
It's important that
versionCode
is an integer - so we can't use semantic versioning here. This is used on the play store to tell which versions come after others - that's why it's tied to git commits ingetGitVersion
versionName
however is shown to users - I'm using semantic versioning here and storing the real value in mypackage.json
. Thanks to https://medium.com/@andr3wjack/versioning-react-native-apps-407469707661
You should be changing your versionCode
and versionName
in android/app/build.gradle
:
android {
defaultConfig {
versionCode 1
versionName "1.0"
{...}
}
{...}
}
Note that versionCode
has to be in an integer that is larger than the ones used for previous releases while versionName
is the human readable version that may be shown to users.