How to update version number of react native app

AndroidReact Native

Android Problem Overview


I am using React native with Android. How can I update version number in the app? As I am getting this error.

I am generating file as per this url https://facebook.github.io/react-native/docs/signed-apk-android.html

I have tried modifying AndroidManifest.xml file, but after I build it, that file gets automatically modified back.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.facebook.react"
    android:versionCode="1"
    android:versionName="1.0" >

Here, I modified the XML:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.facebook.react"
    android:versionCode="2"
    android:versionName="1.1" >

After, build file automatically changes back.

enter image description here

Android Solutions


Solution 1 - Android

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.

Solution 2 - Android

@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 in getGitVersion

  • versionName however is shown to users - I'm using semantic versioning here and storing the real value in my package.json. Thanks to https://medium.com/@andr3wjack/versioning-react-native-apps-407469707661

Solution 3 - Android

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.

Solution 4 - Android

I had the same problem and I checked all the above answer, I had a made a silly mistake because of which nothing worked for me. Just in case any of you do same mistake as mine try this.

  1. Version can be a decimal number like 1.0 or 1.0.1 etc
  2. But VersionCode cannot be decimal number It should be 1,2,3 etc and not 1.1 or 2.2

So in project/app/build.gradle

android {
defaultConfig {
    versionCode 1 // do not use decimal number here
    versionName "1.0" // you can use decimal number here.
    {...}
}
{...}
}

Solution 5 - Android

Set the versionCode under android in app.json:

{
  "expo": {
    "name": "App Name",
...
    "android": {
      "package": "com.app.name",
      "permissions": [],
      "versionCode": 2
    }
  }
}

ref:https://docs.expo.io/versions/latest/workflow/configuration/#versioncodeversion-number-required-by-google-play-increment-by-one-for-each-release-must-be-an-integer-httpsdeveloperandroidcomstudiopublishversioninghtml

Solution 6 - Android

If someone is facing

> wrong version code eg - 31284

Then make sure to not use SeparateBuildPerCPUArchitecture in android/app/build.gradle

def enableSeparateBuildPerCPUArchitecture = false

and

to update the version code and name change in android/app/build.gradle:

android {

defaultConfig {

    versionCode 1
    versionName "1.0"

    {...}
}

{...}
}

Solution 7 - Android

If you're using expo and getting this issue, go to app.json and change the version to a higher number.

{
  "expo": {
    "name": "nameofapp", // btw dont copy this
    "slug": "appslug",   // btw dont copy this
    "version": "1.0.0",  // here is where you change the version
    ...
    ...
    ...
  }
}

You need to also change the version in package.json

{
  ...
  "name": "appname",  // btw dont copy this
  "version": "2.0.0", // here is where you change the version
  ...
  "android": {
    "versionCode": 2,
    ...
  }
  ...
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPraveen PrasadView Question on Stackoverflow
Solution 1 - AndroidJoseph RoqueView Answer on Stackoverflow
Solution 2 - AndroidtgfView Answer on Stackoverflow
Solution 3 - AndroidFrancois NadeauView Answer on Stackoverflow
Solution 4 - AndroidVasanthView Answer on Stackoverflow
Solution 5 - AndroidoOEricView Answer on Stackoverflow
Solution 6 - AndroidkvadityaazView Answer on Stackoverflow
Solution 7 - AndroidAtif KhanView Answer on Stackoverflow