How to update version number of react native app

前端 未结 6 1392
时光说笑
时光说笑 2020-12-12 10:49

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.g

6条回答
  •  执念已碎
    2020-12-12 11:42

    @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

提交回复
热议问题