包详细信息

rn-version-sync

fbluemle597MIT0.1.3

Fast and simple utility to sync React Native version with native code

CFBundleShortVersionString, CFBundleVersion, android, ios

自述文件

rn-version-sync

Fast and simple utility to sync React Native version with native code (Android and iOS).

ci

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 version lifecycle
  • Zero Config: Works out of the box with standard React Native projects

What It Does

  • Syncs package.json version → Android versionName
  • Calculates and sets Android versionCode using formula: 10000*major + 100*minor + patch
  • Syncs package.json version → iOS MARKETING_VERSION (version name)
  • Calculates and sets iOS CURRENT_PROJECT_VERSION (version code)
  • Example: version 1.2.3 produces version code 10203

Installation & Usage

Option 1: One-off execution with npx

npx rn-version-sync

Option 2: Install as dev dependency

npm install --save-dev rn-version-sync
# or
yarn add -D rn-version-sync

Add to your package.json:

{
  "scripts": {
    "version": "rn-version-sync && git add -u"
  }
}

Now when you run:

npm version patch
npm version minor
npm version major

Your native Android and iOS versions will automatically sync!

Options

Verbose mode - See detailed output:

npx rn-version-sync --verbose

Override version code - Manually specify version code:

npx rn-version-sync --version-code 42

By 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.json in 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 10203

iOS 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 + patch

Examples:

  • 1.0.010000
  • 1.2.310203
  • 2.5.1020510
  • 12.34.56123456

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