How to Set Build and Version Number of Flutter App

How to set build and version number of Flutter app

Setting the version and build number

You can update both the version name and the version code number in the same place in pubspec.yaml. Just separate them with a + sign. For example:

version: 2.0.0+8

This means

  • The version name is 2.0.0
  • The version code is 8

This is described in the documentation of a new project (but you might have deleted that if you are working on an old project):

The following defines the version and build number for your application.
A version number is three numbers separated by dots, like 1.2.43
followed by an optional build number separated by a +.
Both the version and the builder number may be overridden in flutter
build by specifying --build-name and --build-number, respectively.
Read more about versioning at semver.org.

version: 1.0.0+1

Re-enabling auto versioning

If your Flutter versioning is not automatically updating anymore, see this answer for how to fix it.

See also:

  • How to get build and version number of Flutter app

How to get build and version number of Flutter app

You can use package_info_plus.

The versions are extracted from:

Android:

build.gradle, versionCode and versionName

iOS:

Info.plist, CFBundleVersion

Usage

Add the dependency

  1. Add this to your package's pubspec.yaml file:
dependencies:
package_info_plus: ^1.0.6

  1. Import the file into your dart file:
import 'package:package_info_plus/package_info_plus.dart';

  1. if your method is marked as async:
PackageInfo packageInfo = await PackageInfo.fromPlatform();

String appName = packageInfo.appName;
String packageName = packageInfo.packageName;
String version = packageInfo.version;
String buildNumber = packageInfo.buildNumber;

If you don't want to use await/async:

PackageInfo.fromPlatform().then((PackageInfo packageInfo) {
String appName = packageInfo.appName;
String packageName = packageInfo.packageName;
String version = packageInfo.version;
String buildNumber = packageInfo.buildNumber;
});

Maintain different version and build number for Flutter app

When building the release version for a Flutter app, you can pass the --build-name and --build-number arguments to override the CFBundleShortVersionString and CFBundleVersion for iOS correspondingly, e.g:

flutter build ios --build-name=1.0.0 --build-number=1.0.0

build-number is used for the internal app version, but you can just set it to the same value. For more info about these arguments, check the documentation (https://flutter.dev/docs/deployment/ios) or run flutter build ios -h in your terminal.

How to change the version number and build number while updating an app in the Google Play Console?

You can change the version number and build in your pubspec.yamal

Example version: 1.0.0+1 to version: 1.0.0+2

Step 1:

Create a new release (in my case open testing the process should be the same for release mode also)

Step 1

Step 2:
Enter details and upload APP bundle

Step 2

App bundel
App bundel

Step 3:
Save => Review Release => Start roll out

Sample Image

Step 4: Wait till the review process is complete

Your app's update is uploaded and pending review.
Step 4 review

Step 5

After the review is done your users will update to the latest version of your app gradually. The update may take some time to reflect in the google play store.

Note:

1)In the above example version number is the same but the build number is different so it is treated as an update in the google play store. But it is highly recommended to change the version number also.

2)The example images provided are from open testing (beta) the process should be the same for the release version also.

How to get build and version number of Flutter Web app

As a temporary workaround you can create a separate file with the version info in it:

web_version_info.dart

class WebVersionInfo {
static const String name = '1.0.0';
static const int build = 1;
}

You can use that for all platforms or in your code you can use kIsWeb to just use it for the web:

Future<String> _getAppVersion() async {
if (kIsWeb) {
return WebVersionInfo.name;
} else {
PackageInfo packageInfo = await PackageInfo.fromPlatform();
return packageInfo.version;
}
}

Of course, this is not a great solution because now you need to remember to update the version and build information in both pubspec.yaml and in WebVersionInfo every time you update the app.

How to force Flutter to update my version and build number?

I got it. It's because my lines in my Info.plist did not look like the following:

    <key>CFBundleShortVersionString</key>     
<string>$(FLUTTER_BUILD_NAME)</string>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>

Anyone has an idea why I had $(MARKETING_VERSION) and $(CURRENT_PROJECT_VERSION)?

Problem with version number in Flutter / pubspec.yaml

You should increment version code always as it is used to identify and push updates internally. You can use any version name which is shown on the play store listing but must increment the number following the plus sign, that is version code.

version: 2.0.3+21


Related Topics



Leave a reply



Submit