How do you configure build and version number in Android application

What is the build version in Android?

Build version is a release number format string identifier that tells about when was application is updated. These numbers are updated by every week, month and year based on the code features.

Build version contains major, versions such as 10,11, an minor versions with decimal such as .5,.2. each version contains more number build iteration numbers.

It contains Codename, Incremental, and Releases value

For example, the Build version is Android SDK: 21 (x.x.x)

The build version gives current running version and updated date.

How do I find the app build version in Gradle ?

This short tutorial is to get the build and version number of an android application.

Android code base uses the gradle build tool which we can configure in build.gradle as seen below These will be located in the project root directory. Gradle file build.gradle: with defaultConfig

defaultConfig {
    applicationId "com.cb.myapp"
    minSdkVersion 20
    targetSdkVersion 29
    versionCode 18
    versionName "1.0"

versionCode is a number specifying the version number of an application submitted to the market place. versionName is a string specify the version name ie.2.0 or 2.0-bugs

Android has official properties for these properties

  • android:versionCode
  • android:versionName

In java, You can To get retrieve this with the BuildConfig class in java, use the following code lines

String versionName = BuildConfig.VERSION_NAME;
int versionCode = BuildConfig.VERSION_CODE;

To get retrieve this with BuildConfig class in Kotlin, You can retrieve using the below line of code

val versionCode = BuildConfig.VERSION_CODE
val versionName = BuildConfig.VERSION_NAME

How to get system version of Android in java

Android API contains [Build.VERSION]( static class that contains following constants

It contains properties Build.VERSION.RELEASE : 9.0 or 9.2 and Build.VERSION.SDK_INT : gives SDK version, it works in API Level 4 onwards.

    String releaseName = Build.VERSION.RELEASE;
    int sdkVersion = Build.VERSION.SDK_INT;
    String str="Android SDK: " + sdkVersion + " (" + release +")";

Difference between versionCode and VersionName(buildnumber) in Android studio

versionCode is a predefined value equal to android:versionCode.

It is an Internal version number used to differentiate between multiple versions with knowing recent versions.

This versionCode does not show apk files to real users in the play store.

It only accepts a number.

VersionName is a string equal to the predefined android:versionName. It is also called a build number.

It is a string format with major and minor versions, “2.1” contains 2 major versions and 1 is a minor version.

You will increase major or minor versions based on bugs or features. It will be visible to end-users in the play store.