rn-version-sync
Fast and simple utility to sync React Native version with native code (Android and iOS).
Features
- Simple & Fast: Minimal dependencies, quick execution
- Auto-detection: Automatically finds Android and iOS files
- Smart Updates: Only modifies version-related lines in native files
- Deterministic Version Codes: Calculates version codes from semver
- npm Integration: Designed to work seamlessly with
npm versionlifecycle - Zero Config: Works out of the box with standard React Native projects
What It Does
- Syncs
package.jsonversion → AndroidversionName - Calculates and sets Android
versionCodeusing formula:10000*major + 100*minor + patch - Syncs
package.jsonversion → iOSMARKETING_VERSION(version name) - Calculates and sets iOS
CURRENT_PROJECT_VERSION(version code) - Example: version
1.2.3produces version code10203
Installation & Usage
Option 1: One-off execution with npx
npx rn-version-syncOption 2: Install as dev dependency
npm install --save-dev rn-version-sync
# or
yarn add -D rn-version-syncAdd to your package.json:
{
"scripts": {
"version": "rn-version-sync && git add -u"
}
}Now when you run:
npm version patch
npm version minor
npm version majorYour native Android and iOS versions will automatically sync!
Options
Verbose mode - See detailed output:
npx rn-version-sync --verboseOverride version code - Manually specify version code:
npx rn-version-sync --version-code 42By default, version code is calculated from semver. Use this option if you need a specific version code that doesn't follow the formula.
Requirements
- Node.js >= 14
- Standard React Native project structure:
package.jsonin project root- Android:
android/app/build.gradle - iOS:
ios/<ProjectName>.xcodeproj/project.pbxproj
Example
Given a package.json with version 1.2.3:
Android build.gradle will be updated:
versionName "1.2.3"
versionCode 10203iOS project.pbxproj will be updated:
MARKETING_VERSION = 1.2.3;
CURRENT_PROJECT_VERSION = 10203;Version code calculation: 10000*1 + 100*2 + 3 = 10203
Version Code Formula
The version code is automatically calculated from semver using the formula:
versionCode = 10000 * major + 100 * minor + patchExamples:
1.0.0→100001.2.3→102032.5.10→2051012.34.56→123456
This ensures:
- Deterministic builds: Same version always produces same version code
- Proper ordering: Higher versions always have higher codes
- Cross-platform consistency: Android and iOS use identical codes
If you need a custom version code, use the --version-code flag.
Similar tools
License
MIT