Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours scrolling social media and waste money on things we forget, but won’t spend 30 minutes a day earning certifications that can change our lives.
Master in DevOps, SRE, DevSecOps & MLOps by DevOps School!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Exploring and Creating a Proof of Concept (POC) to Upload APK Directly from GitHub Package

Automating the process of uploading an APK (or AAB) to the Google Play Store from GitHub can significantly speed up your CI/CD pipeline. By integrating Google Play’s Internal Testing or Beta Testing environments with GitHub, you can automatically trigger a deployment of your Android app whenever you make changes or release a new version on GitHub.

In this post, we’ll explore how to set up a Proof of Concept (POC) to upload an APK from GitHub (from GitHub Actions’ package or release section) directly to the Google Play Store Test Environment (using Fastlane).

What You’ll Need

  1. Google Play Console Account: Access to Google Play Developer API and permissions to upload APKs.
  2. GitHub Repository: A repository with an Android app (APK or AAB).
  3. GitHub Actions: We’ll use GitHub Actions to automate the upload process.
  4. Fastlane: Fastlane is an open-source tool that automates app deployment tasks, including uploading APKs or AABs to Google Play.

Step-by-Step Guide to Automate APK Upload from GitHub to Google Play Store Test Environment

Step1 : Set Up Google Play Developer API Access

To upload your APK automatically from GitHub to the Google Play Store, you’ll need to use the Google Play Developer API. This API allows you to automate the management of your app on the Google Play Console.

  1. Create a Service Account in Google Cloud:
    • Go to the Google Cloud Console.
    • In the IAM & Admin section, create a new service account.
    • Assign the Editor role or appropriate permissions for managing apps in the Google Play Console.
    • Download the JSON key file for your service account.
  2. Enable Google Play Developer API:
    • In your Google Cloud project, search for Google Play Developer API and enable it.
  3. Grant the Service Account Access to Google Play Console:
    • Go to your Google Play Console.
    • Under Settings > API Access, link your Google Cloud project.
    • In the API Access section, add the service account and grant it the Release Manager role.

Step2 : Set Up Fastlane for Google Play Store Deployment

  1. Install Fastlane:
    You can install Fastlane on your local machine or directly in the GitHub Actions workflow using the following commands:
# Install Fastlane using RubyGems
gem install fastlane

Configure Fastlane for Google Play:
In your Android project, initialize Fastlane by running the following command:

fastlane init

During the setup, choose “Google Play” as the platform, and Fastlane will generate the necessary configuration files.

Add Google Play API JSON Key to GitHub Secrets:
For security, store your Google Play Developer API JSON key in your GitHub repository’s Secrets. In your GitHub repository:

  • Go to Settings > Secrets.
  • Add a new secret with the name GOOGLE_PLAY_JSON_KEY and paste the contents of your service account JSON key.

Fastlane Configuration:
Inside the fastlane directory of your Android project, configure the Fastfile. This file will define how Fastlane uploads the APK/AAB to the Google Play Store.

Fastfile example:

lane :deploy do
  # Authenticate using the service account JSON key
  json_key_file = ENV["GOOGLE_PLAY_JSON_KEY"]
  credentials = JSON.parse(json_key_file)
  google_play_service = google_play_credentials({
    json_key: credentials,
  })

  # Upload APK or AAB to Google Play
  upload_to_play_store(
    track: "beta",  # Can be 'alpha', 'beta', 'production', etc.
    aab: "./build/outputs/bundle/release/app-release.aab",  # Path to your AAB
    json_key_file: credentials,
  )
end
  1. This configuration will upload the generated APK or AAB to the beta track in Google Play’s internal testing environment.

Step3 : Set Up GitHub Actions to Automate the Upload

Now that Fastlane is set up, let’s create a GitHub Actions workflow to automate the process of building and uploading your APK from GitHub’s release section to Google Play.

  1. Create a GitHub Actions Workflow File:
    Inside your repository, create the workflow file at .github/workflows/deploy.yml. Example GitHub Actions Workflow (deploy.yml):
name: Upload APK to Google Play

on:
  push:
    tags:
      - 'v*'  # This will trigger the action on version tags, e.g., v1.0.0

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Set up JDK 11
      uses: actions/setup-java@v2
      with:
        java-version: '11'

    - name: Set up Gradle
      uses: gradle/wrapper-validation-action@v1

    - name: Build APK
      run: ./gradlew assembleRelease  # Adjust this if you are using AAB or another flavor

    - name: Set up Fastlane
      uses: fastlane/fastlane-action@v2
      with:
        lane: deploy
      env:
        GOOGLE_PLAY_JSON_KEY: ${{ secrets.GOOGLE_PLAY_JSON_KEY }}

    - name: Upload to Google Play Store
      run: fastlane deploy
      env:
        GOOGLE_PLAY_JSON_KEY: ${{ secrets.GOOGLE_PLAY_JSON_KEY }}

Explanation of Workflow:

  • This workflow listens for push events on tags that start with v, such as v1.0.0.
  • The workflow sets up the environment by installing JDK 11 and Gradle, builds the APK or AAB, and then uses Fastlane to upload the APK/AAB to the Google Play Test Environment (beta).
  • The GOOGLE_PLAY_JSON_KEY secret is used to authenticate with Google Play.

    Step4 : Trigger the Workflow

    Once the workflow is set up, you can trigger it by pushing a tag to your repository. For example:

    git tag v1.0.0
    git push origin v1.0.0
    

    This will automatically trigger the GitHub Actions workflow, which will build your APK and upload it to the Google Play beta track.

    Step 5: Test the APK in the Google Play Test Environment

    After the upload completes, testers you’ve added to the Google Play Console’s beta track will receive an email with a link to download the app. They can start testing the APK or AAB in a real-world environment.

    Related Posts

    Fixing the “Could not find PHP executable” Error in Live Server on VS Code

    this is a common issue and easy to fix! This guide will walk you through the step-by-step solution to get your PHP files running in the browser….

    How to Fix the “npm.ps1 cannot be loaded” Error on Windows When Running npm start

    If you’re a developer working with React or any Node.js-based projects, you may have encountered the following error when trying to run npm start in PowerShell on…

    Simplify Database Migrations with kitloong/laravel-migrations-generator in Laravel

    Laravel provides a powerful migration system that allows developers to easily define and manage database schema changes. However, when working with legacy databases or large projects, manually…

    Understanding and Fixing the “Unable to Read Key from File” Error in Laravel Passport

    Laravel Passport is a powerful package for handling OAuth2 authentication in Laravel applications. It allows you to authenticate API requests with secure access tokens. However, like any…

    How to Generate a GitHub OAuth Token with Read/Write Permissions for Private Repositories

    When working with GitHub, you may need to interact with private repositories. For that, GitHub uses OAuth tokens to authenticate and authorize your access to these repositories….

    Laravel Error: Target class [DatabaseSeeder] does not exist – Solved for Laravel 10+

    If you’re working with Laravel 10+ and run into the frustrating error: …you’re not alone. This is a common issue developers face, especially when upgrading from older…

    0 0 votes
    Article Rating
    Subscribe
    Notify of
    guest
    0 Comments
    Oldest
    Newest Most Voted
    Inline Feedbacks
    View all comments
    0
    Would love your thoughts, please comment.x
    ()
    x