Sub topic 4
Versioning with Version Name and Build Number
Assume you can edit pubspec.yaml and run Flutter commands from a terminal. This chapter uses the standard Flutter version format:
version name + build numberThe version name tells users which release they have. The build number identifies one specific uploaded build.
For example, 1.2.0+7 means:
1.2.0is the version name.7is the build number.
Why Flutter uses two version values
A version name is for people. You might show 1.2.0 in an About screen or in a store listing. It usually follows semantic versioning:
- The first number changes for major, incompatible changes.
- The second number changes for new features.
- The third number changes for fixes.
A build number is for stores and release systems. It distinguishes uploads that have the same version name. You might upload build 7 for testing, discover a problem, and upload build 8 without changing the public version from 1.2.0.
The stores apply different rules to build numbers:
| Platform | User-facing value | Upload value | Common rule |
|---|---|---|---|
| Android | `versionName` | `versionCode` | Each Play upload must have a higher integer |
| iOS | `CFBundleShortVersionString` | `CFBundleVersion` | Each uploaded build needs a new build value |
Set the version in `pubspec.yaml`
The usual source of truth is the version field in the project-level pubspec.yaml file:
# pubspec.yaml
name: my_app
description: Example app
version: 1.2.0+7Flutter uses this value when it generates platform build settings. The Android and iOS projects then receive equivalent platform-specific values.
For a bug-fix release, you could change the value to:
version: 1.2.1+8Change both parts when you publish a new public release. Change only the build number when you need another build of the same public release.
Override the version for a particular build
A command-line build can override the values in pubspec.yaml:
flutter build appbundle --release \
--build-name=1.2.0 \
--build-number=8The --build-name option sets the user-facing version. The --build-number option sets the store build value.
This is useful in continuous integration (CI), which is an automated build system. A CI job can calculate a build number from the run number instead of editing source files. Keep the value predictable and make sure it is higher than every build already uploaded to the target store.
Check the generated platform values
After building, inspect the artifact or platform configuration to confirm the values. Do not assume that a successful compile used the values you intended, especially when CI passes command-line overrides.
The relationship looks like this:
Versioning in a release workflow
A practical workflow separates release planning from build retries:
- Choose the public version, such as
1.3.0. - Assign a new build number, such as
12. - Update
pubspec.yaml, or pass both values in CI. - Build and test the release artifact.
- If the artifact must be rebuilt without changing the public version, increment the build number to
13. - Record the version and build number in release notes.
Never reuse an Android build number for a later Play upload. On iOS, also avoid reusing a build number within the same version. Store each build's source revision and configuration so a crash or support request can be traced back to the exact artifact.
Exercise
You need to upload a second fixed build for public version 2.0.0. The first upload used 2.0.0+41. What version should the second upload use?
Show answer
Use 2.0.0+42. The public version stays 2.0.0, while the build number increases.