Skip to the content.

Automated Build Android Using Github Action

Android CI Download Generated APK AAB Upload Generated APK AAB Scan with Detekt pages-build-deployment Generated APK AAB (Clean)

Version Release

This Is Latest Release

$version_release = 2.2.4

What’s New??

* Update Action Script *
* Update Android Studio Latest Version *
* Update Gradle Latest Version *
* Update Kotlin Latest Version *
* Update Java Version From 11 to 17 *
* Update Java Action version to 3 *
* Update Android SDK Tools * 
* Add Bundletool.jar for workflow github action *
* Add .run configuration *

Article Sources

Guide Sources (Github Action)

Run Using Github Action

How To Use Workflows

Step 1. Upload Your Project on Github

Step 2. Create files github workflows

Step 3. Create Code

name: Generated APK AAB (Upload - Create Artifact To Github Action)

env:
  # The name of the main module repository
  main_project_module: app

  # The name of the Play Store
  playstore_name: Frogobox ID

on:

  push:
    branches:
      - 'release/**'

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      # Set Current Date As Env Variable
      - name: Set current date as env variable
        run: echo "date_today=$(date +'%Y-%m-%d')" >> $GITHUB_ENV

      # Set Repository Name As Env Variable
      - name: Set repository name as env variable
        run: echo "repository_name=$(echo '$' | awk -F '/' '{print $2}')" >> $GITHUB_ENV

      - name: Set Up JDK
        uses: actions/setup-java@v3
        with:
          distribution: 'zulu' # See 'Supported distributions' for available options
          java-version: '17'
          cache: 'gradle'

      - name: Change wrapper permissions
        run: chmod +x ./gradlew

      # Run Tests Build
      - name: Run gradle tests
        run: ./gradlew test

      # Run Build Project
      - name: Build gradle project
        run: ./gradlew build

      # Create APK Debug
      - name: Build apk debug project (APK) - $ module
        run: ./gradlew assembleDebug

      # Create APK Release
      - name: Build apk release project (APK) - $ module
        run: ./gradlew assemble

      # Create Bundle AAB Release
      # Noted for main module build [main_project_module]:bundleRelease
      - name: Build app bundle release (AAB) - $ module
        run: ./gradlew $:bundleRelease

      # Upload Artifact Build
      # Noted For Output [main_project_module]/build/outputs/apk/debug/
      - name: Upload APK Debug - $
        uses: actions/upload-artifact@v3
        with:
          name: $ - $ - $ - APK(s) debug generated
          path: $/build/outputs/apk/debug/

      # Noted For Output [main_project_module]/build/outputs/apk/release/
      - name: Upload APK Release - $
        uses: actions/upload-artifact@v3
        with:
          name: $ - $ - $ - APK(s) release generated
          path: $/build/outputs/apk/release/

      # Noted For Output [main_project_module]/build/outputs/bundle/release/
      - name: Upload AAB (App Bundle) Release - $
        uses: actions/upload-artifact@v3
        with:
          name: $ - $ - $ - App bundle(s) AAB release generated
          path: $/build/outputs/bundle/release/

Step 4. Automated Build on Actions tab on your github repository

ScreenShot

Step 5. Download Artifact

ScreenShot

Extras (Private Repository Succesfully Build Proven)

ScreenShot

Result Generated from Github Action

APK(s) debug generated

ScreenShot

APK(s) release generated

ScreenShot

App bundle(s) release generated

ScreenShot

Clean Up Artifact

name: Generated APK AAB (Clean)

on:
  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

  schedule:
    # Every day at 1am
    - cron: '0 1 * * *'

jobs:
  remove-old-artifacts:
    runs-on: ubuntu-latest
    timeout-minutes: 10

    steps:
      - name: Clean all artifacts
        uses: c-hive/gha-remove-artifacts@v1
        with:
          age: '60 seconds' # '<number> <unit>', e.g. 5 days, 2 years, 90 seconds, parsed by Moment.js
          # Optional inputs
          # skip-tags: true
          # skip-recent: 5

Using Bundle Tool

Step 1. Prepare Bundle Tool

Step 2. Code Action in file android-ci-generate-apk-aab-upload-3.yml

name: Generated APK AAB 2 Bundle Tool (Upload - Create Artifact To Github Action)

env:
  # The name of the main module repository
  main_project_module: app

  # The name of the Play Store
  playstore_name: Frogobox ID

  # Keystore Path
  ks_path: frogoboxdev.jks

  # Keystore Password
  ks_store_pass: cronoclez

  # Keystore Alias
  ks_alias: frogobox

  # Keystore Alias Password
  ks_alias_pass: xeonranger

on:

  push:
    branches:
      - 'release/**'

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v3

      # Set Current Date As Env Variable
      - name: Set current date as env variable
        run: echo "date_today=$(date +'%Y-%m-%d')" >> $GITHUB_ENV

      # Set Repository Name As Env Variable
      - name: Set repository name as env variable
        run: echo "repository_name=$(echo '$' | awk -F '/' '{print $2}')" >> $GITHUB_ENV

      - name: Set Up JDK
        uses: actions/setup-java@v3
        with:
          distribution: 'zulu' # See 'Supported distributions' for available options
          java-version: '17'
          cache: 'gradle'

      - name: Change wrapper permissions
        run: chmod +x ./gradlew

      # Run Tests Build
      - name: Run gradle tests
        run: ./gradlew test

      # Run Build Project
      - name: Build gradle project
        run: ./gradlew build

      # Create APK Debug
      - name: Build apk debug project (APK) - $ module
        run: ./gradlew assembleDebug

      # Create APK Release
      - name: Build apk release project (APK) - $ module
        run: ./gradlew assemble

      # Create Bundle AAB Release
      # Noted for main module build [main_project_module]:bundleRelease
      - name: Build app bundle release (AAB) - $ module
        run: ./gradlew $:bundleRelease

      # - name: Build APK(s) Debug from bundle using bundletool
      #   run: java -jar ".github/lib/bundletool.jar" build-apks --bundle=$/build/outputs/bundle/debug/$-debug.aab --output=$/build/outputs/bundle/debug/$-debug.apks --mode=universal

      - name: Set Env Artifact name from generated aab
        run: |
          cd $/build/outputs/bundle/release/
          files=(*)
          echo "generated_name_aab=${files[0]%.*}" >> $GITHUB_ENV

      # Build APK From Bundle Using Bundletool
      # Noted For Output [main_project_module]/build/outputs/bundle/release/
      - name: Build APK(s) Release from bundle using bundletool (Path same with bundle output)
        run: java -jar ".github/lib/bundletool.jar" build-apks --bundle=$/build/outputs/bundle/release/$.aab --output=$/build/outputs/bundle/release/$.apks --mode=universal --ks="app/$" --ks-pass=pass:$ --ks-key-alias=$ --key-pass=pass:$

      # Duplicate APK(s) Release to zip file and extract
      - name: Duplicate APK(s) Release to zip file and extract
        run: |
          cd $/build/outputs/bundle/release/
          unzip -p $.apks universal.apk > $.apk

      # Upload Artifact Build
      # Noted For Output [main_project_module]/build/outputs/apk/debug/
      - name: Upload APK Debug - $
        uses: actions/upload-artifact@v3
        with:
          name: $ - $ - $ - APK(s) debug generated
          path: $/build/outputs/apk/debug/

      # Noted For Output [main_project_module]/build/outputs/apk/release/
      - name: Upload APK Release - $
        uses: actions/upload-artifact@v3
        with:
          name: $ - $ - $ - APK(s) release generated
          path: $/build/outputs/apk/release/

      # Noted For Output [main_project_module]/build/outputs/bundle/release/
      - name: Upload AAB (App Bundle) Release - $
        uses: actions/upload-artifact@v3
        with:
          name: $ - $ - $ - App bundle(s) AAB release generated
          path: $/build/outputs/bundle/release/

Step 3. Running Action

ScreenShot

Step 4. Waiting Running Action

Waiting for running action

ScreenShot

Check periodically, afraid there is an error

ScreenShot

Step 5. Download Artifact and Extract it

Download Artifact (AAB Artifact)

ScreenShot

Extract it !!! Done

ScreenShot

Run Using Gradle Configuration

.run Configuration (Alternative if you don’t have github action)

Step 1: Create Folder .run on Root Project Directory

ScreenShot

Step 2: Create File [name-config].run.xml

<component name="ProjectRunConfigurationManager">
  <!-- Add Name Configuration Here -->
  <configuration default="false" name="${your-config-name}" type="GradleRunConfiguration" factoryName="Gradle">
    <ExternalSystemSettings>
      <option name="executionName" />
      <option name="externalProjectPath" value="$PROJECT_DIR$" />
      <option name="externalSystemIdString" value="GRADLE" />
      <option name="scriptParameters" value="" />
      <option name="taskDescriptions">
        <list />
      </option>
      <option name="taskNames">
        <list>
          <!-- TODO : add your task here -->
          <option value=":app:assembleDebug" />
        </list>
      </option>
      <option name="vmOptions" />
    </ExternalSystemSettings>
    <ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
    <ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
    <DebugAllEnabled>false</DebugAllEnabled>
    <RunAsTest>false</RunAsTest>
    <method v="2" />
  </configuration>
</component>

Step 3: Your Configuration Will Appears on this Menu

ScreenShot

Step 4: Result run multiple task

ScreenShot

Sample Configuration (signingreport)

<component name="ProjectRunConfigurationManager">
  <configuration default="false" name="signingreport" type="GradleRunConfiguration" factoryName="Gradle">
    <ExternalSystemSettings>
      <option name="executionName" />
      <option name="externalProjectPath" value="$PROJECT_DIR$" />
      <option name="externalSystemIdString" value="GRADLE" />
      <option name="scriptParameters" value="" />
      <option name="taskDescriptions">
        <list />
      </option>
      <option name="taskNames">
        <list>
          <option value="signingreport" />
        </list>
      </option>
      <option name="vmOptions" />
    </ExternalSystemSettings>
    <ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
    <ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
    <DebugAllEnabled>false</DebugAllEnabled>
    <RunAsTest>false</RunAsTest>
    <method v="2" />
  </configuration>
</component>

Colaborator

Very open to anyone, I’ll write your name under this, please contribute by sending an email to me

Name Of Contribute

Waiting for your contribute

Attention !!!

ScreenShot