My Preferred GitHub Actions Setup for Android Projects

My Preferred GitHub Actions Setup for Android Projects
This is the first post in my "Learning in Public" series, i.e. it's basically just my note but in blog post form. Things will probably be too specific just for me, but if you happens to have the exact same issue, great! Glad that I helped.

General idea

  • An action that runs every time something is pushed to main
    • Lint (if I feel like it)
    • Build debug
    • Build release + Publish to Play Store
  • (If I locked the main branch) An action that runs for every Pull Requests
    • Lint (if I feel like it)
    • Build debug

Setup

Step 1: Create .github/workflows/main.yml

Step 2: Setup when it's gonna run

name: Main
on:
  push:
    branches: [ main ]
    paths-ignore:
      - "**/README.md"  

Step 3: Debug build

# Everything in Step 2

jobs:
  debug:
  	runs-on: ubuntu-latest
    steps:
    	- name: Checkout Repo
          uses: actions/checkout@v2
        - name: Setup Java 11
          uses: actions/setup-java@v2
          with:
            distribution: 'adopt'
            java-version: 11
        - name: "Validate Gradle wrapper"
          uses: gradle/wrapper-validation-action@v1
        - name: AssembleDebug
          run: ./gradlew assembleDebug
        - name: Upload Debug APK to GitHub
          uses: actions/upload-artifact@v2
          with:
            name: Debug APK
            path app/build/outputs/apk/debug/app-debug.apk

Step 4: Release build

# Everything in Step 2

jobs:
  # Everything in Step 3
  release-app:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repo
        uses: actions/checkout@v2
      - name: Setup Java 11
        uses: actions/setup-java@v2
        with:
          distribution: 'adopt'
          java-version: 11
      - name: "Validate Gradle wrapper"
        uses: gradle/wrapper-validation-action@v1
      - name: Generate Release AAB
        run: ./gradlew bundleRelease
      - name: Sign Android release
        uses: r0adkll/sign-android-release@v1
        with:
          releaseDirectory: app/build/outputs/bundle/release
          signingKeyBase64: ${{ secrets.SIGNING_KEY }}
          alias: ${{ secrets.ALIAS }}
          keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }}
          keyPassword: ${{ secrets.KEY_PASSWORD }}
      - name: Upload Release AAB to GitHub
        uses: actions/upload-artifact@v2
        with:
          name: Release AAB
          path: app/build/outputs/bundle/release/app-release.aab
      - name: Upload Release AAB to Play Store
        uses: r0adkll/upload-google-play@v1
        with:
          serviceAccountJsonPlainText: ${{ secrets.SERVICE_ACCOUNT_JSON }}
          packageName: # TODO put your package name here
          releaseFiles: app/build/outputs/bundle/release/app-release.aab
          track: # TODO specify track here

Step 5: Create/find all the secrets

Part 1: Generate Release Build
  1. Build AAB in Android Studio (if I haven't done that before)
  2. Make sure I have all the password, alias, everything
  3. Follow the instructions in r0adkll/sign-android-release README
  4. Go to my GitHub project, Settings, and enter all the secrets
Part 2: Upload to Play Store
  1. Make sure Play Store listing is ready.
  2. (To make your life easier, you can use the AAB that you just build to make sure all the release notes and what not are setup properly)
  3. Google the latest tutorial on how to create a service account in GCP
  4. Grab the JSON for the service account
  5. Follow the instructions in r0adkll/upload-google-play README
  6. Go to my GitHub project, Settings, and enter all the secrets

Step 6: Give it a try

Just push to main and see if everything is working as expected

Step 7: Clone everything into PR.yml if I feel like it

And delete the release part and you will be fine.