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 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 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 Kotline, You can retrieve
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 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.