User Tools

Site Tools


android:android_build_configuration

Android Build Configuration

This discusses the process for getting an Android application built for release. It is very cryptic right now, but I wanted to get some of the latest changes to the build process documented somewhere.

Android APKs' require versioning and build number information. Each new APK on the Play Store must have a newer build number than previous APK's. This process attempts to somewhat automate this process. It has yet to be completely tested in reality, but it does seem to work better than the previous manual approach.

To begin with the process takes advantage of Gradle environment variables. Four variables are used, versionMajor, versionMinor, versionHotfix and buildNum. The first three are currently manually set and represent the application version number. 2.4.1 for example. The buildNum variable is retrieved from a Jenkins environment variable or hardcoded to 9999 for desktop builds. The Jenkins build number is always unique for the build being created. The following code block is inserted in the build.gradle file for the Application being built.

// Major.Minor.Hotfix is defined here to identify the build correctly
// These are used in the Manifest to correctly set the versionCode and versionName
// The buildNum must increment for each APK/Bundle built.
 
ext {
    versionMajor  = 2
    versionMinor  = 4
    versionHotfix = 2
    buildNum      = System.getenv("BUILD_NUMBER") as Integer ?: 9999
}

To use this the following code is added to the defaultConfig section of the same build.gradle script.

// Compute the versionCode and versionName which is used in the Manifest to identify the build
versionCode = versionMajor * 1000000 + versionMinor * 10000 + buildNum
versionName = String.valueOf(versionMajor) + "." + String.valueOf(versionMinor) + "." + String.valueOf(versionHotfix)

The code above creates two Gradle environment variables “versionCode” and “versionName”. The versionCode variable is used to create a build number which is substituted into the AndroidManifest.xml for each build. This is the number that must role forward for every APK created. It take the major, minor and build number to create a unique build number. The key is the use of the Jenkins build number which is always moving forward for any given release build. The versionName is just the normal human readable version name such as 2.4.1. It is also used in the AndroidManifest.xml file and is grabbed by the About page in each app.

android/android_build_configuration.txt · Last modified: 2019/08/19 18:35 by timm