How do you configure build and version number in Android application

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

Android code base uses gradle build tool which we can configure in build.gradle as seen below These will be located inside the app 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 market 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 retrieve this with BuildConfig class

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

In Kotlin, You can retrieve using below line of code

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

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 as major versions and 1 is the 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.

Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
You'll get a notification every time a post gets published here.