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
- Add this to your package's pubspec.yaml file:
dependencies:
package_info_plus: ^1.0.6
- Import the file into your dart file:
import 'package:package_info_plus/package_info_plus.dart';
- 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 2:
Enter details and upload APP bundle
App bundel
Step 3:
Save => Review Release => Start roll out
Step 4: Wait till the review process is complete
Your app's update is uploaded and pending 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
What Happens to Older Clients When You Migrate an App Server from Gcm to Fcm
Flutter: How to Fix "A Renderflex Overflowed by Pixels " Error
Recyclerview with Multiple Countdown Timers Causes Flickering
How to Discover Zeroconf (Bonjour) Services on Android? I'M Having Trouble with Jmdns
Want to Load Desktop Version in My Webview Using Uastring
Didn't Find Class on Path: Dexpathlist
How to Paging Query from Firebase Using Android Firebaseui
How to Set a Ripple Effect on Textview or Imageview on Android
Need Some Clarification About Beta/Alpha Testing on The Developer Console
How to Add a Button at The End of Recyclerview
Android in Navigation Drawer When I Click Anywhere Drawer Closes
Getting Error "Gradle Dsl Method Not Found: 'Compile()'" When Syncing Build.Gradle
Is There a Faster Way to Decode HTML Characters to a String Than HTML.Fromhtml()
Supportmapfragment Does Not Support Androidx Fragment
Picture Taken with Camera Intent Is Low Quality on Imageview (7.0+)
Onlistitemclick Is Not Working for Listview
Android/Java: How to Delay Return in a Method
How to Apply Primary Key on the Text Fields in Android Database