Append the following version variable definitions to your app's build.gradle file, this can be anywhere but preferably at the top of the file above all "apply" declarations. You may set the values to your current build/version codes if this is not a new project.
def VERSION_BUILD=0
def VERSION_MAJOR=0
def VERSION_MINOR=0
def VERSION_PATCH=0
In your gradle's default config, update the versionCode and versionName to use the variables declared in the gradle file. This is also where you can make changes to how your version name is displayed (the example below uses the major.minor.patch format), and you can also reuse the variables for example providing a versionName in a release configuration that omits the patch value.
versionCode VERSION_BUILD
versionName VERSION_MAJOR + "." + VERSION_MINOR + "." + VERSION_PATCH
Include the increment_android_version_code and increment_android_version_code actions in your fastlane file, providing them both with the path to your app's build.gradle file, and providing the version name value to update to the increment_android_version_name action.
To commit the version bump to git, simply add your build.gradle path to the default FastLane "git_commit" command.
increment_android_version_code(path: "app/build.gradle")
Increments the "VERSION_BUILD" value in the build.gradle file by one and sets the SharedValues::ANDROID_VERSION_CODE lane context variable.
increment_android_version_name(path: "app/build.gradle", type: "patch")
Increments the version name value in the build.gradle 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.
Bravo! 🎉