So far, I have enjoyed using Fastlane as a CI tool for deployment of APKs on my Android projects. This post is just to build on what my friend Roger wrote about on his detailed 3 part series “Automating the Android Build and Release Process using Fastlane”.
I remember spending hours of research trying to find a config.yml file that would work easily for Gitlab specifically.

# Begin by defining the image to be used, this is what I found as the latest version to work well for Android in 2019/2020
image: openjdk:8-jdk

variables:
  ANDROID_COMPILE_SDK: "28"
  ANDROID_BUILD_TOOLS: "28.0.2"
  ANDROID_SDK_TOOLS:   "4333796"

# PLEASE EDIT THIS PART TO MATCH YOUR PROJECT FOLDER NAME
before_script:

  - cd <<INSERT THE NAME OF YOUR PROJECT FOLDER>>;
  - chmod +x ./gradlew
  - apt-get --quiet update --yes
  - apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1 ruby-full build-essential g++
  - wget --quiet --output-document=android-sdk.zip https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_TOOLS}.zip
  - unzip -d android-sdk-linux android-sdk.zip
  - echo y | android-sdk-linux/tools/bin/sdkmanager "platforms;android-${ANDROID_COMPILE_SDK}" >/dev/null
  - echo y | android-sdk-linux/tools/bin/sdkmanager "platform-tools" >/dev/null
  - echo y | android-sdk-linux/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS}" >/dev/null
  - export ANDROID_HOME=$PWD/android-sdk-linux
  - export PATH=$PATH:$PWD/android-sdk-linux/platform-tools/
  
  # This is important to temporarily disable checking for EPIPE error and use yes to accept all licenses
  - set +o pipefail
  - yes | android-sdk-linux/tools/bin/sdkmanager --licenses
  - set -o pipefail

  # This step installs Fastlane
  - gem install bundler
  - bundle install
  
# This step specifies the stages to be executed when the script is running. For this example, I used only one stage.
# You can have more than one stage listed here. 
stages:
  - build

# This step defines where the release apk is uploaded to on Google Play Store. 
# In this example, it's uploaded to the Beta track/phase when the pipeline in my master branch (on Gitlab) runs successfully.
assembleRelease:
  stage: build
  only:
    - master
  script:
    - ./gradlew assembleRelease
    - bundle exec fastlane beta
  artifacts:
    paths:
    - app/build/outputs/
Here’s a config that can work for you if you are going to integrate Fastlane with Gitlab. I put in short comments to guide you as you set up but you can always reach out in case you get stuck.
Main Reference: