Arrow icon
Deploying Android Apps to Play Store Internal Testing with GitHub Actions and Fastlane

Deploying Android Apps to Play Store Internal Testing with GitHub Actions and Fastlane

Explore the comprehensive guide on deploying Android apps to the Play Store for internal testing using GitHub Actions and Fastlane. This document provides step-by-step instructions on setting up GitHub Actions, Fastlane, and testing the deployment workflow. It also offers best practices, tips, and additional resources for a seamless app deployment process.

Saiful Islam Adar

Senior Frontend Developer

August 4, 2023
Technology
Table of content

As an Android developer, deploying your app to Play Store for internal testing can be a crucial step in the development and quality assurance process. In this article, we will explore how you can automate the deployment process using GitHub Actions and Fastlane. By leveraging these powerful tools, you can streamline your app deployment and ensure a smooth testing experience for your internal team. So, let's get started!

Setting up GitHub Actions

GitHub Actions is a feature-rich workflow automation platform built into GitHub. It allows you to define custom workflows that automatically trigger actions based on various events, such as code commits or pull requests. We are assuming you already know about Fastlane, signing Android application with a key. You can learn more about them here https://docs.fastlane.tools/getting-started/android/setup/

To set up GitHub Actions for your Android app deployment, follow these steps:

A. Creating a Workflow File

Create a workflow file named `deploy-to-playstore.yml` in the `.github/workflows` directory of your repository. This file will define the deployment workflow and its triggers. Here's an outline of the steps involved:


name: Deploy to Play Store
on:
  # Enable manual run
  workflow_dispatch:
    inputs:
      lane:
        description: "Fastlane lane"
        required: true
        default: "internal"
        type: choice
        options:
          - beta
          - promote_to_production
          - internal

# Declare default permissions as read-only.
permissions: read-all

jobs:
  fastlane-deploy:
    runs-on: ubuntu-latest
    steps:
      # Set up Flutter.
      - name: Setup up Flutter
        uses: subosito/flutter-action@v2
        with:
          channel: stable
      - run: flutter doctor -v

      # Checkout the repository
      - name: Checkout repository code
        uses: actions/checkout@v2

      # Setup Ruby, Bundler, and Gemfile dependencies.
      - name: Setup Fastlane
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: "3.2.2"
          bundler-cache: true

      # Configure Keystore.
      - name: Configure Keystore
        run: |
          echo "$PLAY_STORE_UPLOAD_KEY" | base64 --decode > app/upload-keystore.jks
          echo "storeFile=upload-keystore.jks" >> key.properties
          echo "keyAlias=$KEYSTORE_KEY_ALIAS" >> key.properties
          echo "storePassword=$KEYSTORE_STORE_PASSWORD" >> key.properties
          echo "keyPassword=$KEYSTORE_KEY_PASSWORD" >> key.properties
          echo "$PLAY_STORE_CONFIG_JSON" >> fastlane/play_store_config.json
        env:
          PLAY_STORE_UPLOAD_KEY: ${{ secrets.PLAY_STORE_UPLOAD_KEY }}
          KEYSTORE_KEY_ALIAS: ${{ secrets.KEYSTORE_KEY_ALIAS }}
          KEYSTORE_KEY_PASSWORD: ${{ secrets.KEYSTORE_KEY_PASSWORD }}
          KEYSTORE_STORE_PASSWORD: ${{ secrets.KEYSTORE_KEY_PASSWORD }}
          PLAY_STORE_CONFIG_JSON: ${{ secrets.PLAY_STORE_CONFIG_JSON }}
        working-directory: YOUR_APP_DIRECTORY/android

      # Build and deploy with Fastlane.
      - name: Run fastlane
        run: |
          bundle install
          bundle exec fastlane ${{ github.event.inputs.lane || 'internal' }}
        env:
          FASTLANE_JSON_KEY_FILE: fastlane/play_store_config.json
        working-directory: YOUR_APP_DIRECTORY/android

Let's examine the key steps in the workflow:

1. Setting up Flutter: We configure the Flutter SDK in the workflow to ensure the required dependencies are available for building the Android app.

2. Checking out the repository: We fetch the repository code.

3. Setting up Fastlane: We set up Fastlane by using the `ruby/setup-ruby` action, which installs Ruby, Bundler, and the Gemfile dependencies needed for Fastlane.

4. Configuring the Keystore: We configure the Keystore by decoding and extracting the necessary files from the `PLAY_STORE_UPLOAD_KEY` secret. This allows Fastlane to sign the app bundle during the deployment process.

5. Building and deploying with Fastlane: We run Fastlane with the specified lane (`internal` by default) using the `bundle exec fastlane` command. The `FASTLANE_JSON_KEY_FILE` environment variable is set to provide Fastlane with the necessary configuration.

B. Managing Secrets

To securely store sensitive information such as passwords and keys, we use GitHub Secrets. Secrets are encrypted environment variables that can be accessed within GitHub Actions workflows. Here are the secrets required for the Play Store deployment workflow:

- `PLAY_STORE_UPLOAD_KEY`: The base64-encoded contents of your upload keystore file (`upload-keystore.jks`), which is used for signing the app bundle.

- `KEYSTORE_KEY_ALIAS`: The alias of the key in the keystore.

- `KEYSTORE_KEY_PASSWORD`: The password for the key in the keystore.

- `KEYSTORE_STORE_PASSWORD`: The password for the keystore itself.

- `PLAY_STORE_CONFIG_JSON`: The JSON configuration file used by Fastlane to interact with the Play Store API.

Make sure to add these secrets to your GitHub repository under the "Settings" tab, in the "Secrets" section. Refer to the Fastlane documentation for more details on obtaining and managing these secrets.

Setting up Fastlane

Fastlane is a powerful tool that automates the entire iOS and Android app deployment process. It provides a comprehensive set of actions and tools to simplify code signing, building, and publishing your app. Let's configure Fastlane for Play Store deployment:

A. Fastfile Configuration

Create a file named `Fastfile` in the root of your repository. This file defines the Fastlane lanes and their respective actions. Here's an outline of the Fastfile for Play Store internal testing:


update_fastlane

default_platform(:android)

platform :android do
  desc "Submit a new Internal Build to Play Store internal track"
  lane :internal do
    sh "cd .. && cd .. && cd .. && melos bootstrap"
    sh "cd .. && flutter build appbundle"
    upload_to_play_store(
        track: "internal",
        aab: "../build/app/outputs/bundle/release/app-release.aab",
        skip_upload_images: true,
        skip_upload_screenshots: true)
  end
end

In the Fastfile, we define a single lane named `internal`, which represents the workflow for submitting a new internal build to the Play Store. The key actions performed within this lane are as follows:

1. `flutter build appbundle`: We build the app bundle using Flutter, generating the release-ready app bundle file (`app-release.aab`).

2. `upload_to_play_store`: We upload the generated app bundle to the Play Store, targeting the "internal" track. We skip uploading images and screenshots to speed up the deployment process.

Ensure that the paths and configurations in the Fastfile match your project structure and requirements.

Testing the Deployment Workflow

To test the deployment workflow:

1. Commit and push both the workflow file (`deploy-to-playstore.yml`) and the Fastfile to your repository.

2. Navigate to the "Actions" tab on your GitHub repository to view the workflow.

3. Manually trigger the workflow by clicking on the "Run workflow" button. Select the desired lane (e.g., `internal`) from the input options.

4. Monitor the workflow execution in the GitHub Actions console to ensure that each step completes successfully.

5. Check the Play Store internal track to verify that the app bundle has been successfully uploaded.

Best Practices and Tips

To make the most of GitHub Actions and Fastlane for Play Store deployment, consider the following best practices and tips:

1. Store Keystore Files Securely: Ensure that the `PLAY_STORE_UPLOAD_KEY` secret is properly secured and not exposed in your repository or logs.

2. Use Git Tags for Versioning: Consider using Git tags to associate specific versions with your deployments. Fastlane provides actions for tagging releases, making it easy to track and manage your app versions.

3. Test the Workflow Locally: Before committing and pushing changes, test the workflow locally to catch any potential issues or errors. Use the Fastlane CLI and run Fastlane commands directly on your local machine.

4. Monitor Deployment Logs: Keep an eye on the deployment workflow logs to quickly identify and troubleshoot any potential failures. The logs provide detailed information about each step and action taken.

Conclusion

By leveraging the power of GitHub Actions and Fastlane, you can automate the deployment of your Android app to Play Store internal testing. The streamlined process ensures faster and more efficient testing cycles, enabling your internal team to provide valuable feedback and catch bugs earlier. Implement the outlined steps, follow the best practices, and enjoy the benefits of automated app deployment.

Additional Resources

To further explore Android app deployment with GitHub Actions and Fastlane, consider the following resources:

- Fastlane Documentation: Official documentation for Fastlane, providing detailed guides and references.

- GitHub Actions Documentation: Comprehensive documentation on GitHub Actions, covering various aspects of workflow setup and customization.

- Fastlane Plugins: Explore the wide range of community-contributed plugins that extend the functionality of Fastlane.

- GitHub Actions Marketplace: Discover pre-built actions and workflows shared by the GitHub community to enhance your Android app deployment process.

By utilizing these resources, you can continue to enhance your understanding of the tools and techniques required to optimize your Android app deployment workflow.

That concludes our article on deploying Android apps to Play Store internal testing using GitHub Actions and Fastlane. We hope this guide helps you streamline your deployment process and accelerates your app's journey to the hands of your internal testers. Happy coding and testing!

Game Changers Unite

We are the software development agency and we love helping mission-driven startups in turning their ideas into amazing products with minimal effort and time.

LET'S TALK