Introduction To Android CI/CD Pipelines

Introduction To Android CI/CD Pipelines

  • What is CI/CD?

    • CI: Continuous Integration

    • CD: Continuous Delivery or Deployment

  • CI/CD enhances the software development life cycle:

    • Continuous Integration: Developers merge code frequently to a central repository.

    • Continuous Delivery: A review step occurs before deployment.

    • Continuous Deployment: Automates deployment directly after integration.

Key Concepts Discussed

  1. Software Development Workflow

    • Development → Testing → Deployment.

    • CI/CD ensures automation, validation, and efficiency.

  2. CI/CD Workflow Breakdown

    • Event Trigger: A push, pull request, or manual event initiates the workflow.

    • Jobs: Tasks like code build, test, and deployment.

    • Environment: Uses runners (Ubuntu, Windows, or macOS) to execute workflows.

    • Steps: Detailed commands executed sequentially.

    • Artifacts: Generated build files (e.g., APK).

  3. Creating a CI/CD Pipeline Using GitHub Actions

    • Step-by-step process for Android projects:

      • Setup GitHub Repository: Push Android project code to a repository.

      • Define Workflow Directory:

        • .github/workflows/
      • Create Workflow File: Use .yml format to define commands and jobs.

  4. Writing the Workflow (YAML File)

    • Define events:

      • Trigger on push and pull_request for the master branch.
    • Jobs:

      • Environment: Ubuntu runner.

      • Steps:

        1. Checkout the latest code using GitHub Actions.

        2. Set up the Java Development Kit (JDK) environment.

        3. Build the project using Gradle (./gradlew build).

        4. Upload the generated APK as an artifact.

  5. Error Handling and Debugging

    • Debugging missing paths for APK files.

    • Correct setup for Java version (Java 17).

    • Ensuring proper artifact upload paths.

  6. Final Verification

    • Successful CI/CD pipeline execution in GitHub Actions.

    • Downloading the generated APK for testing or release.

Refer below code snap to implement CI/CD in you’re projects:

codename: AndroidBuild
on:
  pull_request:
    branches: [ master ]
  push:
    branches: [ master ]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout Code
        uses: actions/checkout@v4.1.0

      - name: Set Up Java JDK
        uses: actions/setup-java@v3.13.0
        with:
          java-version: '17'
          distribution: 'adopt'

      - name: Grant Execute Permission for Gradlew
        run: chmod +x ./gradlew

      - name: Clean and Build with Gradle
        run: ./gradlew clean build

      - name: Upload Build Artifact
        uses: actions/upload-artifact@v3.1.3
        with:
          name: AndroidDemo.apk
          path: app/build/outputs/apk/debug/app-debug.apk