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
- Google Play Console Account: Access to Google Play Developer API and permissions to upload APKs.
- GitHub Repository: A repository with an Android app (APK or AAB).
- GitHub Actions: We’ll use GitHub Actions to automate the upload process.
- 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.
- 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.
- Enable Google Play Developer API:
- In your Google Cloud project, search for Google Play Developer API and enable it.
- 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
- 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
- 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.
- 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 withv
, such asv1.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.