CI/CD with GitHub Actions helps you automatically build, test, and deliver your Android app. It saves time and reduces mistakes by doing these steps for you.
0
0
CI/CD with GitHub Actions in Android Kotlin
Introduction
You want to test your Android app every time you change the code.
You want to build your app automatically before sharing it.
You want to send your app to testers or app stores without doing it manually.
You want to catch errors early by running tests on every update.
You want to keep your app delivery fast and reliable.
Syntax
Android Kotlin
name: Android CI/CD
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Build with Gradle
run: ./gradlew build
- name: Run tests
run: ./gradlew testThe on section tells when the workflow runs, like on code changes.
The jobs section defines steps like building and testing your app.
Examples
This runs the workflow only when you push code to the main branch.
Android Kotlin
on:
push:
branches: [ main ]This job runs on a Linux machine and checks out your code.
Android Kotlin
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3This step builds the debug version of your Android app.
Android Kotlin
- name: Build with Gradle
run: ./gradlew assembleDebugThis step runs your app's unit tests to check for errors.
Android Kotlin
- name: Run unit tests run: ./gradlew test
Sample App
This GitHub Actions workflow runs when you push code to the main branch. It checks out your code, sets up Java 17, builds your Android app using Gradle, and runs tests.
Android Kotlin
name: Android CI/CD
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Build with Gradle
run: ./gradlew build
- name: Run tests
run: ./gradlew testOutputSuccess
Important Notes
Make sure your Android project has a working gradlew script in the root folder.
You can add more steps to upload build files or notify your team.
Use the runs-on setting to choose the operating system for your build.
Summary
GitHub Actions automates building and testing your Android app.
Workflows run on code changes to keep your app healthy.
Simple YAML files define what steps to run and when.