Skip to content

Instantly share code, notes, and snippets.

@mkloouo
Created December 20, 2024 10:00
Show Gist options
  • Select an option

  • Save mkloouo/ff8f71ff6ff29526308f9b9632371577 to your computer and use it in GitHub Desktop.

Select an option

Save mkloouo/ff8f71ff6ff29526308f9b9632371577 to your computer and use it in GitHub Desktop.
How to easily update React Native app semantic/build versions

TL;DR

This script automates the process of updating:

  • The package.json version.
  • Xcode target versions.
  • Android Gradle version names.

It ensures the build numbers are synced across both iOS and Android platforms.


1. Add Scripts and Dependencies to package.json

Add the following entries to your package.json:

{
  "scripts": {
    "bump-version:build": "npx react-native bump-version --skip-semver-for all",
    "bump-version:type": "npx react-native bump-version --reset-build --type"
  },
  "dependencies": {
    "rn-bump-version": "^1.0.0"
  }
}

2. Align iOS and Android Versions

Ensure the following mappings between iOS and Android:

  • Version (version name) should be identical.
  • Build number (version code) should be identical.

Example:

iOS Configuration
iOS Screenshot

Android Configuration
Android Screenshot


3. Increment the Build Number

To increase the build number without changing the version:

npm run bump-version:build  # or yarn bump-version:build

The build number will increment by 1. The version remains unchanged.


4. Update the Version (Resets the Build Number)

To update the semantic versioning (semver) and reset the build number to 1:

Bump the Major Version:

From 1.2.32.0.0

npm run bump-version:type major  # or yarn run bump-version:type major

Bump the Minor Version:

From 1.2.31.3.0

npm run bump-version:type minor  # or yarn run bump-version:type minor

Bump the Patch Version:

From 1.2.31.2.4

npm run bump-version:type patch  # or yarn run bump-version:type patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment