Package Exports
- rn-build-version
- rn-build-version/lib/versionManager.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rn-build-version) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
rn-build-version
A React Native tool for managing versionCode and versionName in your Android build.gradle file, with support for building APKs and AABs. It simplifies version management by providing interactive prompts and automates backups and changelog updates.
Features
- Version Management:
- Increment patch (e.g.,
0.0.1→0.0.2), minor (e.g.,0.0.1→0.1.0), or major (e.g.,0.0.1→1.0.0) versions. - Set custom
versionCodeandversionName. - Skip version updates for local testing builds.
- Increment patch (e.g.,
- Automation:
- Backup
build.gradlebefore modifications. - Generate or update a
CHANGELOG.mdfile with version details.
- Backup
- Flexibility:
- Custom Gradle file path support via CLI option.
- Dry-run mode to simulate changes without applying them.
Prerequisites
- Ensure your build.gradle contains versionCode and versionName (e.g., in defaultConfig).
- Configure signing in build.gradle for release builds.
Notes
- The tool assumes a standard React Native Android project structure.
- Run chmod +x android/gradlew on macOS/Linux if Gradle permissions are an issue.
Installation
Install the package globally or as a development dependency in your React Native project:
# Globally
npm install -g rn-build-version
# As a dev dependency
npm install --save-dev rn-build-versionUses
1. Add Scripts to Your package.json
Integrate the tool into your React Native project by adding these scripts:
{
"scripts": {
"build:android:apk": "rn-build-version && cd android && ./gradlew clean assembleRelease",
"build:android:aab": "rn-build-version && cd android && ./gradlew clean bundleRelease",
"build:android:apk:local": "cd android && ./gradlew clean assembleRelease",
"build:android:aab:local": "cd android && ./gradlew clean bundleRelease"
}
}2. Run the Commands
- Production Builds (with Version Management):
npm run build:android:apk
npm run build:android:aabThese commands prompt you to update the version before building.
- Local Testing Builds (No Version Change):
npm run build:android:apk:local
npm run build:android:aab:localThese skip version prompts and build with the current version.
3. CLI Usage
Run the tool directly with options:
rn-build-version [options]Option Description Default
-g, --gradle
Examples
- Use a custom Gradle path:
rn-build-version --gradle ./custom/path/build.gradle- Simulate changes (dry-run):
rn-build-version --dry-run- Combine options:
rn-build-version --gradle ./android/app/build.gradle --dry-runExample Interaction
When you run rn-build-version or a build script with it, you’ll see:
Current versionCode: 1
Current versionName: 0.0.1
? What do you want to do with the version? (Use arrow keys)
> Increment patch (e.g., 0.0.1 -> 0.0.2)
Increment minor (e.g., 0.0.1 -> 0.1.0)
Increment major (e.g., 0.0.1 -> 1.0.0)
Set custom version
Skip (no increment)Choosing "Increment patch":
- Updates to versionCode: 2, versionName: "0.0.2".
- Creates a backup (build.gradle.bak).
- Appends to CHANGELOG.md.
Choosing "Set custom
- Prompts for new versionName and versionCode.
- Example: Set versionName: "1.2.3", versionCode: 123.