Android CI/CD pipeline with Github Actions: Demystifying Github Actions | by Ankur Anurag

nearly Android CI/CD pipeline with Github Actions: Demystifying Github Actions | by Ankur Anurag will lid the most recent and most present counsel on the order of the world. entry slowly subsequently you comprehend capably and accurately. will accrual your information precisely and reliably


Producing and deploying Android builds has at all times been a ache level for Android builders. A whole lot of improvement hours are wasted as we stare on the pc display screen, ready for our construct to finish. That is the place CI/CD involves our rescue. There are numerous instruments for constructing CI/CD pipelines like Jenkins, CircleCI, Bitrise, TravisCI, and so on. Github Actions is a brand new addition to this listing. It makes the entire technique of constructing a pipeline very straightforward and is totally free for public repositories. You could find the costs right here.

On this article, I’d reveal methods to use Github Actions to automate your Android construct and deployment course of.

One can create the workflow file by going to Actions tab > Configure Workflow your self.

This can take you to the YAML editor, the place we’ll outline our workflow in response to our want. A fundamental workflow construction seems like this:

# Title of your workflow
title: Android Construct and Deployment Pipeline
# Outline on which Github occasion, workflow will set off
on:
push:
branches: [ master ]
pull_request:
branches: [ main ]
jobs:
job1:
title: Job 1
runs-on: ubuntu-latest
steps:
- title: 'Examine Inputs'
run: echo 'Job 1'

Observe that the YAML file is delicate to indentation

  1. Add a set off for Github occasions
on:
push:
branches: [ master ]
pull_request:
branches: [ main ]

You may also add triggers for merges, pull requests, and so on.

2. Add assist for guide activation (if wanted)

workflow_dispatch:
inputs:
app_id:
description: 'The appliance Id/package deal title'
required: true
department:
description: 'The department from which you need the construct'
required: true
default: 'grasp'

3. Cost code

Default department:

- title: Checkout the code to particular department
makes use of: actions/[email protected]

Particular department (department title from Step 2 entries, may also be onerous coded)

- title: Checkout the code to particular department
makes use of: actions/[email protected]
with:
ref: $ github.occasion.inputs.department

4. Configure JDK

We’ve one predefined motion on the Github Actions Market. It handles the duty of downloading the JDK, unzipping it, configuring the JAVA_HOME approach and so on

- title: Arrange JDK
makes use of: actions/[email protected]
with:
distribution: 'zulu'
java-version: '11'

5. Configure the Android SDK

We’ve one motion for this step as effectively. Obtain SDK, unzip, env variables, settle for licenses, it is all dealt with.

- title: Setup Android SDK
makes use of: android-actions/[email protected]

6. Gradle caching (non-obligatory)

For this we’ll use this motion .

- makes use of: actions/[email protected]
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: $ runner.os -gradle-$ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties')
restore-keys: |
$ runner.os -gradle-

7. Make Gradle executable

We’ll use the bash command for this.

- title: Make gradlew executable
run: chmod +x ./gradlew

8. Generate the artifact

For package deal:

- title: Generate app bundle.
run: ./gradlew app:bundleRelease --stacktrace

For APKs:

- title: Generate app APK.
run: ./gradlew assembleRelease --stacktrace

9. Signal the artifact

If in case you have outlined the signing configuration within the gradle file, then this step will not be needed.

To signal the APK/Bundle, you have to KeyStore Password, Alias, Key Password. You possibly can outline them as world variables in Github on the group or repository degree. These secrets and techniques are encrypted and protected to make use of on Github Actions. To create secrets and techniques you may go to this hyperlink

- title: Signal app bundle
run: |
jarsigner -keystore app/*.jks
-storepass $ secrets and techniques.KEY_STORE_PASSWORD -keypass $ secrets and techniques.KEY_PASSWORD
app/construct/outputs/bundle/launch/app-release.aab $ secrets and techniques.ALIAS

There is a motion for a similar. We will additionally use it.

- title: Signal app bundle
makes use of: r0adkll/[email protected]
id: sign_app
with:
releaseDirectory: app/construct/outputs/bundle/launch
signingKeyBase64: $ secrets and techniques.SIGNING_KEY
alias: $ secrets and techniques.ALIAS
keyStorePassword: $ secrets and techniques.KEY_STORE_PASSWORD
keyPassword: $ secrets and techniques.KEY_PASSWORD
env:
# override default build-tools model (29.0.3) -- non-obligatory
BUILD_TOOLS_VERSION: "30.0.2"

10. Add the artifact to Github (non-obligatory)

In case you need to entry the package deal/APK generated within the above steps, you may add it to Github. It is going to be out there for obtain throughout the workflow.

- title: Add Bundle
makes use of: actions/[email protected]
with:
title: signed_app_bundle
path: app/construct/outputs/bundle/launch/app-release.aab

11. Create Launch to Playstore

We’ll use a default motion for this function.

To launch to the PlayStore, we want a service account json file, which is created from the PlayStore console. The steps concerned are past the scope of this text. You possibly can comply with this hyperlink to create service account json file.

steps:
- title: Create service_account.json
run: echo '$ secrets and techniques.SERVICE_ACCOUNT_JSON ' > service_account.json
- title: Deploy to Play Retailer
makes use of: r0adkll/[email protected]
with:
serviceAccountJson: service_account.json
packageName: $ github.occasion.inputs.app_id
releaseFiles: app/construct/outputs/bundle/launch/*.aab
observe: inside
whatsNewDirectory: whatsnew/
mappingFile: app/construct/outputs/mapping/launch/mapping.txt
inAppUpdatePriority: 5

I hope the article virtually Android CI/CD pipeline with Github Actions: Demystifying Github Actions | by Ankur Anurag provides acuteness to you and is beneficial for including as much as your information

Android CI/CD pipeline with Github Actions: Demystifying Github Actions | by Ankur Anurag

x