How do you configure build and version number in Android application


This short tutorials talks about how to get build and version number of an android application.

Android code base uses gradle build tool which we can configured 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 specify the version number of an application submitted to market versionName is an string specify the version name ie.2.0 or 2.0-bugs

Android has official properties for this 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 Kotline, You can retrieve

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

Difference between versionCode and VersionName(buildnumber)

versionCode is a predefined value equal to android:versionCode.

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

This versionCode is not shown to real users for apk file in playstore.

It only accepts number

VersionName is an string equal to predefined android:versionName. These is also called build number.

This is an string format with major and minor version, “2.1” contains 2 as major version and 1 is minor version.

You will increase major or minor version based on bugs or features. This will be visible to end users in playstore

THE BEST NEWSLETTER ANYWHERE
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
Subscribe
You'll get a notification every time a post gets published here.