Create a property file named "version.properties" in the project root directory which contains the following properties. You may set the values to your current build/version codes if this is not a new project.
VERSION_BUILD=0
VERSION_MAJOR=0
VERSION_MINOR=0
VERSION_PATCH=0
Next in the project root directory, create a new gradle file which will contain the methods used to read the version.properties file. These can be found in the common-methods.gradle file which will expose methods "readBuildCode()" and "readVersionName()". The default version name format is major.minor.patch but this can be changed by altering the returned value in the "readVersionName()" method.
In your apps build.gradle file, where your versionCode and versionName configuration is defined, add the following apply from line to the top of this file (under any apply plugin lines) and update your versionCode and versionName to call the methods provided by the common-methods.gradle file.
apply from: "$rootDir/common-methods.gradle"
versionCode readBuildCode()
versionName readVersionName()
To commit the version bump to git, simply add your version.properties path to the default FastLane "git_commit" command.
increment_android_version_code(path: "version.properties")
Increments the "VERSION_BUILD" value in the version.properties file by one and sets the SharedValues::ANDROID_VERSION_CODE lane context variable.
increment_android_version_name(path: "version.properties", type: "patch")
Increments the version name value in the version properties file, the specific value to be updated (major, minor, or patch) is defined by the "type" parameter passed to the method. When updating the major version, the minor and patch values are reset to zero, similarly when updating the minor version, the patch value is reset to zero. This also sets the SharedValues::ANDROID_VERSION_NAME lane context variable.