How to Get the Build/Version Number of Your Android Application

How do I get my application Version in Android

This page has a tips on how to do it from java:

PackageManager manager = context.getPackageManager();
PackageInfo info = manager.getPackageInfo(
context.getPackageName(), 0);
String version = info.versionName;

Also, this link has official information on how to properly set up your application versioning.

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;
});

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

Get current app's build version - Xamarin.Android

For version name:

Application.Context.ApplicationContext.PackageManager.GetPackageInfo(Application.Context.ApplicationContext.PackageName, 0).VersionName

For version code:

Application.Context.ApplicationContext.PackageManager.GetPackageInfo(Application.Context.ApplicationContext.PackageName, 0).VersionCode

How to change Android version and code version number?

Go in the build.gradle and set the version code and name inside the defaultConfig element

defaultConfig {
minSdkVersion 9
targetSdkVersion 19
versionCode 1
versionName "1.0"
}

screenshot



Related Topics



Leave a reply



Submit